c++ - Is the size of a vector simply the size of the sum of its parts? -


for example, float 4 bytes. mean vector containing 10 floats 40 bytes?

a std::vector has 3 different sizes. there size of vector object , size(std::vector<some_type>). size isn't useful though. typically size of 3 pointers how vector typically implemented.

the second size returned size() member function. value returned number of elements in vector. "size" people use when talking size of vector.

the last size vector has total number of elements has allocated currently. obtained using capacity member function.

so vector holding 10 floats needs use @ least 10 floats worth of memory using more capacity() allowed grater size(). size of vector object (sizeof(name_of_vector)) value , value never change no matter how many elements add vector.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -