Hi,
When storing a bunch of items and I don't need random access to the container, I am using an std::list
which is mostly fine. However, sometimes (esp. when I just push back entries to the back and never delete somewhere in the middle), I wish I had some structure with better performance for adding entries.
std::vector
is bad because:
- It must reallocate if it doesn't fit anymore.
- It doesn't really work for huge amounts of data (because you just cannot always get very big chunks of continuous free memory).
std::list
is bad because:
- It makes an allocation on every single push_back. That is slow and leads to a lot of memory fragmentation.
So, something in between is what I want.
Basically, I want something like std::list< boost::array<T, 100> >
or so. Or maybe instead of 100
, let it be 4096/sizeof(T)
. Maybe also std::list< std::vector<T> >
and the first vectors can be small and then further ones can grow. Actually I want to have that hidden from the usage, so I can just do a mycontainer.push_back(x)
.
std::rope
is a bit similar to that but it is not available in the standard.
Is there something like this in Boost or so?
Thanks, Albert