Код: Выделить всё
T *pobj = new(pstorage);
Afaiu Следующий код не дает гарантии для чрезмерных типов.
Код: Выделить всё
// properly aligned heap storage to hold N contiguous T objects
unsigned char *storage = new unsigned char[N*sizeof(T)];
< /code>
operator new// can be on the stack or on the heap
template
struct Storage {
alignas(T) unsigned char storage[N * sizeof(T)];
}
auto *wrapped_storage = new Storage;
auto *storage = wrapped_storage.storage;
< /code>
But it works only if the number of objects is known at compile-time.
What would be the proper way to get a raw storage suitably aligned of over-aligned types?
Подробнее здесь: https://stackoverflow.com/questions/787 ... igned-type
Мобильная версия