Follow up to What the heque is going on with the memory overhead of std::deque?
Visual C++ manages deque
blocks according to the container element type using this:
#define _DEQUESIZ (sizeof (value_type) <= 1 ? 16 \
: sizeof (value_type) <= 2 ? 8 \
: sizeof (value_type) <= 4 ? 4 \
: sizeof (value_type) <= 8 ? 2 \
: 1) /* elements per block (a power of 2) */
This results in very large memory footprint for small elements. By changing the 16 in the first line to 128 I was able to drastically reduce the footprint required for a large deque<char>
. Process Explorer Private Bytes dropped from 181MB -> 113MB after 100m push_back(const char& mychar)
calls).
#define
? deque
block
sizing? push_back
calls to
deque<char>
? <deque>
code?Deque can have additional memory overhead over vector because it's made of a few blocks instead of contiguous one.
As the quote from cppref states, std::deque uses multiple arrays to store the elements. Within each array the elements are contiguous.
Unlike lists, deques don't include a . sort() method to sort the sequence in place. This is because sorting a linked list would be an inefficient operation.
In C++, the STL deque is a sequential container that provides the functionality of a double-ended queue data structure. In a regular queue, elements are added from the rear and removed from the front. However, in a deque, we can insert and remove elements from both the front and rear. Deque Data Structure.
gcc has
return __size < 512 ? size_t(512 / __size) : size_t(1);
with a comment
/* The '512' is
* tunable (and no other code needs to change), but no investigation has
* been done since inheriting the SGI code.
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With