
that's the answer on YOUR implementation...do NOT make assumptions about how all are implemented. At Monday 2004-06-14 20:58, you wrote:
Bo Peng wrote:
I read /usr/include/c++/3.2.2/bits/stl_vector.h, here is the answer to my own questions:
1. How is size() implemented in vector<>?
end - start pointer. Not a reference to a variable. Too bad.
2.Since I will have a lot of such arrays, I would also like to know how many additional variables vector<int> keeps. I.e. exactly how big is vector<int> arr(5)?
sizeof(int)*5 + sizeof(pointer)*3 since vector keeps three pointers: start, end and end_of_storage. I am glad to find that when I initialize vector with a parameter, there is no additional storage allocated. arr.resize(5) of an empty array will not cause additional storage allocation either.
It might be trivial to copy boost::array and add constructor/destructor but I do not want to re-invent the wheel.
I am using typedef'ed vector now. I will use a modified boost::array later because I will be able to improve performance with a const size() and save some memory by using only one additional data member.
Bo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"