The following program on running with g++ 4.8.2
gave the output 12 on a 32-bit Linux system:
vector<char> v;
cout << sizeof(v) << endl;
I saw this and know that sizeof(v)
could be implementation specific. Still, I was wondering what might be causing that vector to have a size of 12. What I think is that the iterators v.begin()
and v.end()
might be contributing to 8 bytes of the size. Am I correct? If yes, what is contributing to the remaining 4 bytes of size? If not, what are these 12 bytes all about?
Take a look at the sources. libstdc++
is part of the gcc download.
Anyway, the container must have these members:
char*
.size_t
or char*
.size_t
or char*
.[[no_unique_address]]
instead).In theory, 2 and 3 might be smaller if not pointers. Though that would be curious, as it would restrict the maximum size.
Also in theory, 2 and 3 could be allocated dynamically with the data. Haven't found anyone actually do that though.
Together 12 bytes, as expected.
Double the sizes for a 64-bit implementation.
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