The HeapAlloc function does not indicate the guarantee of alignment on the MSDN page, but I am inclined to think that it should have the same GlobalAlloc guarantees, which guaranteed to return 8-byte memory memory (although it relies on undocumented functions for this is evil); in the end, he explicitly said that Global / LocalAlloc is just wrappers around HeapAlloc (although they can drop the first n bytes to get consistent memory, but I think this is very unlikely).
If you really want to be sure, just use GlobalAlloc or even VirtualAlloc, whose granularity is the granularity of the page, which is usually 4 KB (IIRC), but in this case you will waste a lot of memory for small allocations.
By the way, if you use the new C ++ operator, you are guaranteed to correctly align the memory for the type you specify: this may be the way to go.
Matteo italia
source share