Boost logo

Boost Users :

From: Bo Peng (bpeng_at_[hidden])
Date: 2004-06-14 22:58:02

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.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at