You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
VirtualAlloc is not a heap. It is a page allocator. Pages are rather large, often 4KB. VirtualAlloc cannot be used to allocate part of a page. As such you're wasting space for small allocations by allocating entire pages, and you're also not optimizing for the case where the alignment is less than the size of a page so you can just allocate some pages and assume they have the correct alignment.
The text was updated successfully, but these errors were encountered:
As such you're wasting space for small allocations by allocating entire pages
Yep, but that's kind of the use case I had in mind: Large allocations with large alignment requirements (as in, many pages each).
I could just use HeapAlloc, but I don't know of a way to free all excess memory: HeapReAlloc isn't able to free, say, the first few bytes of an allocation (moving the allocation upwards to an aligned address), it can only free the "tail" by making the allocation smaller, so it still wastes a fair bit of memory in bad cases. An allocation aligned to X bytes will waste up to X-1 bytes - since I'm using this to allocate memory aligned to up to 1 MB, this is unacceptable.
That said, perhaps a good solution would be to use VirtualAlloc for requests that are at least a page in size (or have size plus alignment larger than the page size), and HeapAlloc for everything smaller (the memory wasted by using it should be less than the memory wasted by allocating a whole page, if the threshold is good).
you're also not optimizing for the case where the alignment is less than the size of a page
Right. This fix is simpler, so I might do that later.
VirtualAlloc
is not a heap. It is a page allocator. Pages are rather large, often 4KB.VirtualAlloc
cannot be used to allocate part of a page. As such you're wasting space for small allocations by allocating entire pages, and you're also not optimizing for the case where the alignment is less than the size of a page so you can just allocate some pages and assume they have the correct alignment.The text was updated successfully, but these errors were encountered: