I want to have a little class which manages raw memory with this API
template<class allocator = std::allocator<char> >
class raw_memory
{
static_assert(std::is_same<char, typename allocator::value_type>::value,
"raw_memory: allocator must deal in char");
public:
raw_memory() = default;
raw_memory(raw_memory&&) = default;
raw_memory&operator=(raw_memory&&) = default;
explicit raw_memory(size_t, allocator const& = allocator());
~raw_memory(); // deletes any memory
char*get(); // returns pter to (begin of) memory
void resize(size_t); // re-allocates if necessary, may delete old data
size_t size() const; // returns number of bytes currently hold
raw_memory(raw_memory const&) = delete;
raw_memory&operator=(raw_memory const&) = delete;
raw_memory(raw_memory&) = delete;
raw_memory&operator=(raw_memory&) = delete;
};
The template parameter allocator
allows for different memory alignment options.
I was thinking about using std::unique_ptr<char, Deleter>
, as a member (or base) (plus a size_t
holding the number of bytes). What to use as Deleter? Or is there a better way to achieve all that?