I need to allocate large regions of memory (megabytes) with large alignments (also potentially in the megabyte range). The VirtualAlloc family of functions don\'t seem to p
Yes, you can use the same technique. VirtualAlloc
a large range as MEM_RESERVE
. Find the sub-range that is appropriately aligned and call VirtualAlloc
a second time on the sub-range with MEM_COMMIT
.
Have a look at the source for _aligned_malloc
in the windows/MSVC crt, its very simple to use the same method to align virtual memory, i'd would even go so far as to say, just replace its internal malloc
call (same goes for _aligned_free
), this allows allocation with only a single system call.
However, why do you need such massive alignment? Are you trying to abuse address bit patterns for fast memory block slabs?