What do you want to do exactly, do you want to know how much memory a std::vector
that contains 8 or 16 char
s takes up?
If that's what you want, your code above is wrong. What your code above shows is the size of a std::vector
, in which the elements are an array of char
s. It gives you the size of the std::vector
object itself - but doesn't say anything about the amount of memory that the elements take up. That memory is allocated dynamically by the vector
.
It's not possible to know this with the sizeof
operator, because sizeof
is a compile-time operator, while the memory for the elements is dynamically allocated at runtime.