STL STL queue memory usage versus vector?

I was wondering exactly how much memory is used in the queue compared to the vector. I had a problem the other day when I had an array of int queues that used around 60 MB, and when the same data was put into a vector of vectors, which it used about 4 MB. Is this a mistake on my part in coding a program, or that stl queues usually use more memory than vectors?

+5
source share
1 answer

std::queueis a container adapter, not the container itself. So compare the overhead of some real containers:

  • std::vectorvery memory efficient, it uses almost zero overhead. A std::vector<int>uses about 4 bytes per element, on most platforms.

  • std::listvery memory inefficient, it is likely to use two overhead pointers for each item. A std::list<int>uses about 24 bytes per element on 64-bit platforms and 12 bytes on 32-bit platforms.

  • std::dequeis between the two, and this is the default container for std::queue. According to “what happens with the excess memory, std::deque” the MSVC decomponent is a list of blocks, each of which contains about 16 bytes, which is quite a bit of overhead if your queues contain one or two inteach and you have many queues.

, , , , . 15 , - , .

, , . , Boost circular_buffer. std::vector std::deque deque. , , STL. , .

.

+12

All Articles