View Single Post
Old May 26th, 2006, 5:46 PM   #13
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
Quote:
Originally Posted by nnxion
A side question: I see Soulstorm doing:
void stash::clearStash(){
	currentSize = 0;
	currentStorage = 0;
	ch = new char [0];
	next = currentStorage - currentSize;
}
So he doesn't delete [] anything, will new do a resize next time it's called (like realloc)?
That is exactly what I have noticed right now... you beat me to it. The problem is, that when I try to do this:
//--reset the stash
void stash::clearStash(){
	delete [] ch;
	ch = new char [gIncrement];
	currentSize = 0;
	currentStorage = gIncrement;
	next =  gIncrement - currentSize;
}
and this main:
int main(){
	stash o("hello world");
	
	
	stash b;
	b = o;
	
	o.show();
	b.show();
	return 0;
}
I get this error:
Quote:
C++ tool 3(1885) malloc: *** Deallocation of a pointer not malloced: 0x8fe067a8; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug
currentStorage: 12
current size: 11
Next: 1
hello world
currentStorage: 12
current size: 11
Next: 1
hello world
I thought this method (deleting and reallocatind 'ch') worked out quite well in inflate()...

What went wrong?
__________________
Project::Soulstorm (personal homepage)
Soulstorm is offline   Reply With Quote