palmer@mcnc.org (Thomas C. Palmer) (07/05/90)
I'm having a problem resizing an array of pointers. I have a class
Array that has members:
Type** ary;
int sz;
The constructor allocates the array with:
...
ary = new Type*[sz = size];
...
If the array needs to be resized I call the following:
void Array::resize(int newsz) {
Type** oldary = ary;
int i, oldsz = sz;
sz = ((newsz != 0) ? newsz : (sz < 2 ? (2) : (sz+sz/2)));
ary = new Type*[sz];
for(i=0; i<oldsz; i++) ary[i] = oldary[i];
for(; i<sz; i++) ary[i] = 0;
delete oldary;
}
The delete statement seems to hose the free store; if removed, everything
works. I've tried the following replacements with no success:
delete *oldary;
delete [oldsz] oldary;
delete [oldsz] *oldary;
What am I doing wrong? I'm using g++ 1.37.0 on a Sun 4 (4.0.3).
-Tom
Thomas C. Palmer North Carolina Supercomputing Center
Cray Research, Inc. Phone: (919) 248-1117
PO Box 12889 Arpanet: palmer@ncsc.org
3021 Cornwallis Road
Research Triangle Park, NC 27709