This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to clear the nested vector?



----- Original Message ----- From: "Mr. H. Xia" <h.xia@sheffield.ac.uk>
To: "libstdc++" <libstdc++@gcc.gnu.org>
Sent: Tuesday, April 19, 2005 4:50 PM
Subject: How to clear the nested vector?



Hi, all

I am having problems with clearing a nested vector.

for example:

// face class, a user defined class.
class face{
int *A;
public:
void setup(unsigned n){
  if(!A) A = new int [n];
}

~face() {delete[] A}
};


Shouldn't this have a copy constructor as well?



// define the nested vector. vector< vector<face> > x;

// somewhere
x.resize(100);

// somewhere
face f;
f.setup(5);
x[20].push_back(f);

/*
 .
 .
 .
 .
*/

x.clear();


but later when I clear x, the memory is not decreasing...


Can someone tell me what is wrong with my procedure? Many thanks!

Note: on Win32 with either VC6.0 , a simple x.clear() is working, but on Linux no way is working.

That is a known bug in VC6.0, which is fixed in later versions. x.clear() should destroy the members of the vector, but is should not release the memory.



Bo Persson




-- Johnix






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]