www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/16/07:18:39

From: Endlisnis <s257m AT unb DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with ostrstream object
Date: Sat, 15 May 1999 22:07:40 -0400
Organization: BrunNet
Lines: 49
Message-ID: <373E286C.8CCA33A@unb.ca>
References: <373d931a DOT 0 AT uni-wuerzburg DOT de>
NNTP-Posting-Host: ftnts1c20.brunnet.net
Mime-Version: 1.0
X-Mailer: Mozilla 4.51 [en] (Win95; U)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019