Mail Archives: djgpp/1999/05/16/07:18:39
"Bernd König" wrote:
> When running the program the system begins to swap until the error message:
> Virtual memory exceeded in 'new'. I suppose that the memory for the object
> is not realy released after deleting. Is it a bug in the c++ library or of
> Win95? I'm thankful for your help.
Your program didn't include the right h files, and main didn't return 'int'
as it should, but that wasn't causing your problem (I'm just being picky).
I looked at it further and I found some very odd behaviour of "ostrstream".
I have added line numbers for clairity. This program exibits the same problem,
it runs out of memory. I tried debugging it, and each time, "wandler" gets a
new segment of memory, eventually exhausting the supply. The odd part is if you
remove Line09 & Line11, then this problem goes away and wandler always get
allocated the same space. To make things even stranger if you remove Line08,
then on Line09 'a' get assigned '0x0', which is fine, but this also happens on
Line11. It seems that if "str()" returns NULL once, it will return NULL always.
My observations:
1. Accessing the "str()" method makes the object not deallocate when you try to
"delete" it.
2. Accessing the "str()" method before assigning anything to the string means
all subsiquent attempts to get the "str()" method will return '0x0' even if
something is in the string.
Line01:#include <strstream.h>
Line02:
Line03:int main()
Line04:{
Line05: while(1)
Line06: {
Line07: ostrstream *wandler = new ostrstream;
Line08: wandler -> operator<<(10.0);
Line09: char* a = wandler -> str();
Line10: wandler -> operator<<(10.0);
Line11: a = wandler -> str();
Line12: delete wandler;
Line13: }
Line14: }
--
(\/) Endlisnis (\/)
s257m AT unb DOT ca
Endlisnis AT HotMail DOT com
ICQ: 32959047
- Raw text -