I need to allocate a buffer that is at aligned to a 32 bit boundary (4 bytes).
Will std::make_shared do that? I think it is likely but don't know if it can be guaranteed... as the basic alignment requirement for uchar is one byte.
Most implementations of std::make_shared will align a char to a pointer alignment (8 bytes), but it is not guaranteed, And therefore this is not portable.
If you want a portable buffer with a specific alignment then use std::aligned_storage, which must have the correct alignment with make_shared, you can use the overload of make_shared that creates an array of objects if you want to decide the buffer size at runtime, and you want to watch out for the strict aliasing rule when treating it as another type.
As per @TedLyngmo as aligned storage is deprecated in C++23, to make it future-proof you should make your own aligned buffer type
Why is std::aligned_storage to be deprecated in C++23 and what to use instead?
std::aligned_storage is/will be deprecated (since C++23).std::aligned_storage requires to know the buffer size at compile-time. OP didn't tell if it's the case.vector of the intended type with a custom allocator would be more suitable.
std::make_shared<uchar>will not create a buffer anyway, just ashared_ptron a singleuchar. Maybe you want to create an aligned unsigned char array then pass it to the third constructor there? Does your requirement be that you'll store objects all suitably aligned in the buffer?sizeof) of your object must be a multiple of its alignment.alignof(uchar)is, whatever that may be.