I have to allocate an array of pointers. The pointers are about 5000.
The array is about 5000*4 = 20Kb
Should I use VirtualAlloc and waste some bytes (because of the page granularity) or should I use HeapAlloc?
If I call VirtualAlloc I know that my array is page aligned, wich is the best in terms of speed
But if I call HeapAlloc, do I have some kind of alignment?
I need speed optimization and not size optimization
The array is about 5000*4 = 20Kb
Should I use VirtualAlloc and waste some bytes (because of the page granularity) or should I use HeapAlloc?
If I call VirtualAlloc I know that my array is page aligned, wich is the best in terms of speed
But if I call HeapAlloc, do I have some kind of alignment?
I need speed optimization and not size optimization
For speed optimization always use VirtualAlloc it is the fastest and best. The page size is only 4KB so you are wasting an insignificant amount of memory anyway, granularity is not an issue with 20KB. though for something as small as 20K any allocation scheme is just about as fast as any other.
I will use VirtualAlloc.
Confirmed - HeapAlloc pages are always dword-aligned :)