When creating a struct, I often zero it using struct initialization:
struct MyStruct data = { 0 };
However, I have a very large (200mb) struct that I'm allocating, and because it has strict alignment needs (math library using AVX), I'm allocating it using _mm_alloc
:
struct MyStruct* data = (struct MyStruct*)_mm_malloc( sizeof (struct MyStruct), 32 );
To zero this struct, memset
works fine. However, if I try to use struct initialization here, it crashes with a Segmentation Fault:
*data = (struct MyStruct) { 0 };
Am I doing this improperly for a dynamically allocated struct? Or is there some other reason why a strictly-aligned block of allocated memory can't be initialized in this way?