www.delorie.com/archives/browse.cgi | search |
Newsgroups: | comp.os.msdos.djgpp |
From: | manfred DOT heumann AT uni-bielefeld DOT de (Manni Heumann) |
Subject: | Re: Problem with ostrstream object |
References: | <373d931a DOT 0 AT uni-wuerzburg DOT de> |
X-Newsreader: | News Xpress 2.01 |
Date: | Sun, 16 May 1999 11:54:31 GMT |
NNTP-Posting-Host: | ppp36-121.hrz.uni-bielefeld.de |
Message-ID: | <373eb1ca.0@news.uni-bielefeld.de> |
X-Trace: | 16 May 1999 13:53:46 +0200, ppp36-121.hrz.uni-bielefeld.de |
Lines: | 41 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
"Bernd König" <koenig AT physik DOT uni-wuerzburg DOT de> wrote: >Hi, >i found a problem with the ostrstream class (djgpp and gnu compiler under >Win95). Somewhere in >my program i have to create and remove an ostrstream object many times (i.e. >endless). It looks >like this: > >#include <iostream.h> >#include <stdio.h> > >void main() >{ >while(1){ > { > ostrstream *wandler = new ostrstream; > wandler -> operator<<(10.0); > wandler -> str(); > delete wandler; > } >} >} > > >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. > >B. Koenig > It's not a bug at all! When you call the member str(), your strstream gets frozen and the memory won't be released when you delete your object. You will either have to unfreeze the stream by calling wandler->freeze (0) or simply delete the array that str() returns (delete wandler->str()). Btw: There is no need to create wandler dynamically with new as strstreams handle their memory themselves. Manni
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |