1

The guide "Using Singly Linked Lists" uses _aligned_malloc to allocate the SLIST_HEADER structure before calling InitializeSListHead() on it. Is it a requirement that the list header structure is placed on the heap? I mean, it's declared with DECLSPEC_ALIGN(16) (on Win64), the compiler would place it on a required 16-byte boundary, won't it?

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • I don't understand, why you are contrasting heap allocation with memory alignment. It's not like those two concepts ever compete. What question do you really want to ask? – IInspectable Apr 06 '16 at 15:38
  • The real question is - is there any particular reason this C++ sample uses malloc() for the header? – Seva Alekseyev Apr 06 '16 at 15:51

1 Answers1

1

The giveaway here is the mix of libraries. The SLIST part comes from Windows itself (doesn't assume C/C++) while _aligned_malloc comes from the MSVCRT. Since the SLIST code cannot even assume MSVCRT is used, it doesn't know where the memory came from.

So it doesn't matter by which means you (or the compiler) align the memory, or how your language calls a particular category of memory. (Your "heap" most likely isn't a Windows Heap in the HeapAlloc sense of the word)

MSalters
  • 173,980
  • 10
  • 155
  • 350