From kde-devel Tue Aug 06 21:00:46 2002 From: aleXXX Date: Tue, 06 Aug 2002 21:00:46 +0000 To: kde-devel Subject: Re: c++ question: alloc'ing and free'ing arrays X-MARC-Message: https://marc.info/?l=kde-devel&m=102866889431109 On Saturday 03 August 2002 20:05, Marcos Dione wrote: > a friend of mine is developing a class that has lots of arrays of > different types (POD and non-POD types), and the class must resize ... > delete[] array; > array= new int[size] > > in the resize method. with non-POD types, she uses ctor ? > npt **npa; > > npa= NULL; > > npa= new npt* [size] > for (int i= 0; i npa[i]= new npt; dtor ? > for (int i= 0; i delete npa[i]; > delete[] npa; resize ? > if (npa!=NULL) { > for (int i= 0; i delete npa[i]; > delete[] npa; > } > npa= new npt* [size] > for (int i= 0; i npa[i]= new npt; > > in the same places respectively. Lazy workaround: use a container data structure, e.g. QPtrList from Qt or a list from the STL (or a vector). > now, the problem is that in certain circumstances the resize methods > segfault in the new (!!!) statement. using gdb, running the test > program I get this backtrace: ... > code works on other circumstances, like in the constructor. I hope you > can give me a hint on what's going on... also, I would like to know > about any lib that can store and retrieve objects to/from disk. as you The data contained in the objects has to be serialized/marshalled in order to be stored on disk. You could use a QDataStream, or create a XML document, or something else :-) > can see, she's trying to parse a Network from an istream. What do you mean by "parse a network from an istream" ? What do you want to do ? Bye Alex >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<