Does this mean that malloc() is fine for AVX2 (32 byte alignment) nowadays?
"Any memory that's allocated dynamically via new or malloc is guaranteed to be properly aligned for objects of any type, but buffers that are not allocated dynamically have no such guarantee"
Conversation
Replying to
Probably not, no.
I'm not sure where this specific quote came from, but when you find them in language specifications it only applies up to some "standard alignment" which is basically that of the built-in types.
On x86 this is usually 16 bytes on Linux-alikes and 8 on Windows.
1
5
In C++ you can see the alignment of std::max_align_t to find this maximum alignment. malloc() usually only supports this maximum alignment: since it is untyped, the only way it could do better would be to unconditionally use larger alignments for large enough allocations.
2
Maximum size/alignment types are also inherently problematic because most implementations don't ever want to change them and therefore change the platform ABI. Even if they wanted to raise max_align_t to 32 bytes, maxint_t to 128-bit, etc. it would technically break the ABI.


