I use AVX2 intrinsic in my program, and declare a __m256i variable in one of the class, like the following:
class A {
protected:
__m256i buffer;
public:
A() {
buffer = _mm256_setzero_si256();
}
};
When I create an instance of A, if the memory location of buffer is not 32-byte aligned, I got a Seg Fault. Is there a way to force either the return address from new operator or the memory address of buffer to be 32-byte aligned?
I don't think you need placement new:
Now simply inherit from
AlignedNew<32>
.See also this proposal, which has been accepted for C++17: Dynamic memory allocation for over-aligned data.