Hi. I’m in need of 32 byte aligned memory blocks.
I currently do it myself using malloc and creating more memory, then shifting the start point to the alignment point. It’s a classic way of doing it, but it’s a bit messy. I’d like to use Juce’s MemoryBlock and other arrrays to align to 32 bytes as well.
Is this possible?
Hi,
I am not aware of any support for alignment in juce::MemoryBlock or HeapBlock, but C++17 introduced std::aligned_alloc - that might be a bit cleaner to use than the classic way you’ve described?
CHOC has an aligned memory block:
Thanks for the replies guys. So there’s no way Juce memory allocations can do it? It’s a shame as any SIMD(256 bit) work crashes if it’s not aligned to 32.
Strangely, with c++17 or c++20 in Windows it doesn’t appear to exist yet. I could use _aligned_malloc on Windows and posix_memalign on Mac, I just wondered if there was something more universal?
I’ll stick with my own alloc’s then, it’s just weird seeing memory allocations all over my code again! ![]()
![]()
It should be , try including cstdlib its been available since 17
Thanks for confirming, you’ve used it on windows LLVM clang with Visual Studio 2022?
I ask because standards aren’t always features.
Yeah I’m not sure exactly, but I would be suprised if it wasn’t. https://en.cppreference.com/w/cpp/header/cstdlib.html
I haven’t tried it but unfortunately it does look like it really isn’t supported by MSVC
aligned_allocsupport is missing, because of the Windows heap implementation. The alternative is to use_aligned_malloc.
Thanks for finding that. The good news is that it’s not just me. No problem really, although it would be nice to have an alignment feature included with MemoryBlock.
