I'm trying to define a Data
object that contains its size, followed by size
bytes of data.
Something like:
struct Data {
size_t size;
char data[1];
static void* operator new( std::size_t size, size_t dataSize ) {
return ::operator new( size+dataSize-1 );
}
static void operator delete( void* data ){
::operator delete( data );
}
Data( size_t size ) : size(size) {
std::memset( data, 0, size );
}
};
This works, and I can allocate it with placement new:
Data* data = new (3) Data( 3 );
I'd like to create a std::unique_ptr<Data>
and, as good practice, I'd prefer to use std::make_uinque
, over a raw new
.
Is it possible to call std::make_unique<Data>
passing it the data for placement-new?
Any version of the C++ standard is fine.