Is there any known header-only STL-like container/allocator for appending chunks of memory to another continuos memory area until it's filled? At the moment I am using a std::vector<char> vec
, because it has some useful interface, but it's not optimal and somehow I think I am abusing it for my needs.
I first use std::vector::reserve
to fix its capacity and allocate the required memory once for all to avoid unnecessary reallocations and then use std::copy(&chunk[0], &chunk[size], vec.data() + vec.size())
each time to append the new chunks of memory to the unfilled
memory area behind the vector (of course size() <= capacity()
). After each copy I explicitly update the size of the vector accordingly. Ok, I could use a back_inserter. But this not the point now (see below).
Of course std::copy
could be specialized for char
by any implementation so that it can just call memcpy
at the end, but this is not a guarantee. Calling memcpy
by myself to append the chunk to the memory already allocated by the vector to have such guarantee is just ugly. Are there better/more elegant options?
EDIT: I have no control on how the chunks of memory are allocated. They are given.