I designed this smart buffer. I'd use std::vector
but I don't want to copy things, I want to use a ready buffer and I want it to be self deleted when Buffer
gets deleted.
struct Buffer
{
public:
std::unique_ptr<uint8_t *> data;
size_t len = 0;
Buffer(CBuffer cBuffer)
{
data = std::make_unique<uint8_t *>(cBuffer.data);
len = cBuffer.len;
}
Buffer(bool empty)
{
data = std::make_unique<uint8_t *>(nullptr);
this->len = 0;
}
bool empty = false;
};
The problem with this buffer is that I get errors like this:
error: cannot initialize a parameter of type 'unsigned char *const *' with an lvalue of type 'uint8_t *' (aka 'unsigned char *')
auto b = return_something(raw_buffer, buffer.len);
in
uint8_t* raw_buffer = *buffer.data;
auto b = return_something(raw_buffer, buffer.len);
What is unsigned char *const *
? And will this Buffer
work and delete the managed buffer on destruction?