A std::vector contains a buffer of continuous memory internally for a given type, with the exception of bools. Is there anyway of constructing a vector by specifying this buffer such that no coping of data is required?
I have a C api which gives me a buffer of data of a certain type. I would like to be able to manipulate this data via the functionality associated with std::vector, such as std::vector<>::iterator, begin(), end() etc.
Maybe you have a better suggestion as to how I might work with these buffers, as they are huge and I don’t wish to copy them.
The api allocates the memory and provides a function which I call to tell it to release it again.
Why dont you just wrap the buffer in a simple class containing the functions you want to be able to use.
Something like this will probably suffice, using the fact that pointers are iterators.
Now you can use it kinda like a vector:
If you also want to manage the memory that the buffer contains then you’ll need to add a destrtuctor and remove the default copy constructor and assignment operator.