In short, at least clang 8 and 8.3 optimize code in such a way than it should be aligned more than default malloc \ new alignment (that is alignof(max_align_t), typically 8).
Since the code targets C++11, we can either use platform_specific functions like posix_memalign and _aligned_malloc, or we can overallocate and use standard std::align to get address with desired alignment.
I choose latter for cross-platform and because I don't know how it works for consoles, so we now allocate size(T) + alignof(T) + sizeof(Header), and Header now also stores original pointer from malloc.
Detailed version is in this issue: https://github.com/bombomby/optick/issues/77
In short, at least clang 8 and 8.3 optimize code in such a way than it should be aligned more than default
malloc
\new
alignment (that isalignof(max_align_t)
, typically 8).Since the code targets C++11, we can either use platform_specific functions like
posix_memalign
and_aligned_malloc
, or we can overallocate and use standard std::align to get address with desired alignment.I choose latter for cross-platform and because I don't know how it works for consoles, so we now allocate
size(T) + alignof(T) + sizeof(Header)
, andHeader
now also stores original pointer frommalloc
.