Myriachan
2018-11-09 19:50:00 UTC
The C++17 / C11 aligned_alloc() function is effectively unimplementable in
Windows. At least, not without updating the whole operating system.
The fundamental flaw with aligned_alloc() is that aligned_alloc() cannot be
implemented on top of an existing malloc() implementation because of the
need for free() to be able to free aligned_alloc() pointers. It has to be
integrated directly into the heap manager - which in the case of Windows
programs is not controlled by the application.
I suppose that it is possible to implement aligned_alloc() in Windows by
having all memory allocations at the C runtime level have an extra header
before calling Win32's HeapAlloc, but then you're hurting all malloc()s
just for the sake of supporting a very rare aligned_alloc().
This is really an unfortunate design flaw; if there were instead a separate
aligned_free() that were required, this wouldn't be a problem. Visual
Studio already has custom functions _aligned_malloc() and _aligned_free().
I don't work for Microsoft; I'm just pointing out something I know from
working with it so much.
Thanks,
Melissa
Windows. At least, not without updating the whole operating system.
The fundamental flaw with aligned_alloc() is that aligned_alloc() cannot be
implemented on top of an existing malloc() implementation because of the
need for free() to be able to free aligned_alloc() pointers. It has to be
integrated directly into the heap manager - which in the case of Windows
programs is not controlled by the application.
I suppose that it is possible to implement aligned_alloc() in Windows by
having all memory allocations at the C runtime level have an extra header
before calling Win32's HeapAlloc, but then you're hurting all malloc()s
just for the sake of supporting a very rare aligned_alloc().
This is really an unfortunate design flaw; if there were instead a separate
aligned_free() that were required, this wouldn't be a problem. Visual
Studio already has custom functions _aligned_malloc() and _aligned_free().
I don't work for Microsoft; I'm just pointing out something I know from
working with it so much.
Thanks,
Melissa
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.