I have a few related questions about managing aligned memory blocks. Cross-platform answers would be ideal. However, as I\'m pretty sure a cross-platform solution does not
The trickiest requirement is obviously the third one, since any malloc()
/ realloc()
based solution is hostage to realloc()
moving the block to a different alignment.
On Linux, you could use anonymous mappings created with mmap()
instead of malloc()
. Addresses returned by mmap()
are by necessity page-aligned, and the mapping can be extended with mremap()
.