<flyn...@tutanota.com> wrote: > Hello, > > Does CHICKEN align a block of memory to the page boundary when I declare > a vector of 4096 elements? If not, how to make it aligned to the page > boundary? >
Hi! Sorry for the very late reply! Are you talking about regular Scheme vectors storing any kind of Scheme data, or SRFI-4 vectors (only able to store numbers)? In the first case you might want to know that each slot of the vector is a machine word in size (32 bits or 64 bits depending on your machine and operating system). In both cases you also have to concider that every compound Scheme data is stored in memory with a little header, so that takes some space in addition to the data that is effectively stored. Lastly, you also have to be aware that regular Scheme data is allocated in garbage collected memory, which in the case of CHICKEN, does not guarantee any alignment outside of word size alignment, and that the data will move around when a garbage collection is triggered. Ways around this exist: - With SRFI-4 vectors, you can ask for allocation in static memory (non garbage collected, effectivelly using malloc) with the NONGC argument to make-XXvector: https://wiki.call-cc.org/man/5/Module%20srfi-4#constructors - With regular Scheme vectors, you can use object-evict to copy your object to static memory https://wiki.call-cc.org/eggref/5/object-evict#object-evict - You can also write a custom procedure in C that would allocate some static memory directly but that’s a little more involved as you have to format the data correctly (putting the right header, etc…) Also, as a side note, because I don’t know if that fits your use case, you can allocate memory in C and access it from Scheme with a pointer, using the pointer related procedures: https://wiki.call-cc.org/man/5/Module%20(chicken%20memory)#srfi-4-foreign-pointers I hope everything is clear and that it answers your question! If not, don’t hesitate to ask! _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users