The documentation for _alloca()
says here:
The _alloca routine returns a void pointer to the allocated space, which is guaranteed to be suitably aligned for storage of any type of object.
However, here it says:
_alloca is required to be 16-byte aligned and additionally required to use a frame pointer.
So it seems that in the first reference they forgot about 32-byte aligned AVX/AVX2 types like __m256d
.
Another thing that confuses me is that the first page says _alloca()
is deprecated, while it suggests to use instead a function that may allocate memory from the heap rather than the stack (which is unacceptable in my multi-threaded application).
So can someone point me whether there is some modern (perhaps, new C/C++ standard?) way for aligned stack memory allocation?
Clarification 1: Please, don't provide solutions which require the array size to be compile-time constant. My function allocates variable number of array items depending on run-time parameter value.
_alloca
is not part of either of them. – user2100815alloca
align allocation on 16byte. if you need another align - allocate more memory and align yourself – RbMmstd::aligned_storage
work for your needs? You can specify the alignment as the second template parameter and it comes from the stack given the example implementation which usesalignas
. en.cppreference.com/w/cpp/types/aligned_storage – Joealignof(__m256d)
, for the benefit of people who don't have your platform extensions? – Kerrek SB