This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: vector<> can probably never grow to it's maximum size!
On Wed, 2004-10-20 at 20:50, Paolo Carlini wrote:
> Dhruv Matani wrote:
>
> >Yes, I have attached a file containing the test results.
> >
> >
> For which test and which parameters? The last numbers are too small
> to be meaningful.
This one ;-)
>
> Paolo.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
The price of freedom is responsibility, but it's a bargain, because
freedom is priceless. ~ Hugh Downs
#include <stddef.h>
#include <cstddef>
#include <iostream>
#include <vector>
#include <string>
#include <ext/bitmap_allocator.h>
// #define ALLOC_ std::allocator
// #define ALLOC_ __gnu_cxx::__mt_alloc
#define ALLOC_ __gnu_cxx::bitmap_allocator
using namespace std;
int ctor = 0;
int dtor = 0;
#define INNER_CLASS float
//std::vector<int>
// string
#define INITIALIZER1 1024
// "Small string"
//
struct one
{
INNER_CLASS i;
one() : i(INITIALIZER1) { }
one(const one& _other) : i(_other.i)
{ ++ctor; }
~one() { ++dtor; }
};
int main()
{
int ctr = 0;
int x = 300000;
cout<<sizeof(one)<<", "<<(64/sizeof(one)+1)<<endl;
while (x--)
{
const int initial_sz = 64 / sizeof(one) + 1;
std::vector<one, ALLOC_<one> > ov(initial_sz);
for (int i = 0; i < initial_sz - 2; ++i)
{
ov.push_back(one());
}
++ctr;
}
cout<<"Copy ctor called: "<<ctor<<" times.\n"
<<"Destructor called: "<<dtor<<" times."<<endl;
}