The vector<bool>
class in the C++ STL is optimized for memory to allocate one bit per bool
stored, rather than one byte. Every time I output sizeof(x)
for vector<bool> x
, the result is 40 bytes creating the vector structure. sizeof(x.at(0))
always returns 16 bytes, which must be the allocated memory for many bool
values, not just the one at position zero. How many elements do the 16 bytes cover? 128 exactly? What if my vector has more or less elements?
I would like to measure the size of the vector and all of its contents. How would I do that accurately? Is there a C++ library available for viewing allocated memory per variable?