I would like to find a way to store several std::vectors
, each of a different but known and reasonably small size, in contiguous memory. I realize I could write my own class, say with a very large array and with pointers to the start of each subsection of the array within the larger array treated like a separate entity, but it seems like there should be a smarter way to do this.
Is there a way to use allocators
, for example, to create contiguous std::vectors
? I'd like not to reinvent the wheel just because I want this memory-locality of otherwise normal std::vectors
I don't know how to even begin coding. I need to create an allocator that takes a pointer to memory, allocates a vector there, and then somehow passes back the address of the end of that vector, so the next std::vector
's allocator could grab that and do it again. How can an allocator
return a value?
std::array<T,N>
instead? It is much easier to place them in memory, and since you are not growing your vectors, the unnecessary member functions, such aspush_back(...)
, would be gone. Of course if you are on pre-C++11, this wouldn't be an option. – Doddstd::vector<T, std::allocator<T>>
? Because using a custom allocator affects the vector type. – Yokostd::vector<int>&
argument. – Yoko