3

Is there some way to align HeapAlloc?

There is _aligned_malloc, but I'd like to use HeapAlloc since I frequently allocate memory on a private heap.

Abc Def
  • 51
  • 5
  • 2
    For C, see [How to allocate aligned memory only using the standard library?](https://stackoverflow.com/questions/227897/how-to-allocate-aligned-memory-only-using-the-standard-library/227900#227900). You'd use the result from `HeapAlloc()` in place of `malloc()`, presumably. I don't think there's a simple alternative for C++ — the languages C and C++ are different, and never more so than in the area of memory management. – Jonathan Leffler Jul 13 '20 at 21:31
  • Like I said, man, there's also the `_aligned_malloc` function I know of, but these functions allocate memory on the process' default heap, while I wish to allocate memory on a private heap since whenever I allocate large amounts of data on the process heap then free it, it does not get released back to the OS the majority of the time, while if I destroy my private heap it is. – Abc Def Jul 13 '20 at 21:33
  • Read the answer — it covers how to deal with allocations as if from `HeapAlloc()`. It only got edited to mention [`aligned_alloc()`](http://port70.net/~nsz/c/c11/n1570.html#7.22.3.1), which is the C11 standard function for aligned allocation, a number of years after it was first written. – Jonathan Leffler Jul 13 '20 at 21:34
  • My bad, I just skimmed over it quickly. – Abc Def Jul 13 '20 at 21:35

0 Answers0