Win32 memory allocation with large alignment

后端 未结 2 777
遥遥无期
遥遥无期 2021-01-13 19:23

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

相关标签:
2条回答
  • 2021-01-13 19:26

    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.

    0 讨论(0)
  • 2021-01-13 19:49

    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?

    0 讨论(0)
提交回复
热议问题