Is there a std container in c++ that acts like a hybrid between a vector and a linked list. What I mean is a data structure that overcomes the frequent reallocation overhead of std::vector and potential excess memory allocation, instead when the structure runs out of space it adds a pointer to the next allocated fragment, and only when the number of fragments reaches a certain value, the entire structure is de-fragmented into a continuous new chunk and number of fragments is set back to 0.
Share
std::dequeis the closest standard container to what you describe. It is not exactly like this, however (for example, it pretty much has to be an array of arrays rather than a list of arrays since the latter wouldn’t permit constant-time element access).Depending on your practical requirements, it might be close enough.