-
I tried global N00bish of me to ask, but what's the way to go here? =) (Notes. I did verify the segfault/UB at my end is directly due to the mere presence of I should add that the actual realloc call that heap-allocs those MyStruct arrays isn't hand-written but in a macro-generated List type's macro-generated Add method. Generally works totally fine for all other (non-mat4s-containing) struct types. So I'd rather not just willy-nilly hardcode some special-cased one-off alignment stuff into there, but anyway eager to learn about the options here =) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
For now, I found the only workaround (an ugly one) that lets me keep This must have come up before with |
Beta Was this translation helpful? Give feedback.
-
Hi @metaleap, The CGLM library makes alignment optional via the To fully respect In its current definition, #ifdef __AVX__
# define CGLM_ALIGN_MAT CGLM_ALIGN(32)
#else
# define CGLM_ALIGN_MAT CGLM_ALIGN(16)
#endif |
Beta Was this translation helpful? Give feedback.
What is blowing up your alignment is the realloc() call in add
It seems random probably because sometimes realloc() is returning 32 byte aligned addresses and sometimes addresses aligned to less than 32 bytes (then the memory sanitizer throws an exception).
The C standard has no aligned_realloc(), Windows has _aligned_realloc(). As for other OSs, there might be some malloc like library that offers aligned_realloc(). When sticking with the standard library, you could do what you already do, aligned_alloc() + memcpy(); or request extra bytes to realloc(), align the address and memmove():