How to measure the overall memory consumption of an STL container?

As in the header: if an object is specified like some STL container (for example, std::vector<int>or std::set<MyClass>), I would like to know their memory consumption --- this is --- how much memory is consumed to store the elements, auxiliary data for each element and the size of the container. I assume that the stored objects do not allocate any extra memory.

With a, std::vector<int> vI can add:

sizeof(std::vector<int>) + v.capacity()*sizeof(int)

because vectors do not store any auxiliary data for each element. But how to do this for other containers?

I can live with inconsistent time complexity.

+5
source share
1 answer

STL , . .

+5

All Articles