[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Deallokering og flushing af strstream-buffer



On Tue, 31 Jul 2001, Emil Zeuthen wrote:

> Goddag,
>
> Jeg arbejder i øjeblikket på et C++-program hvor jeg benytter et > > objekt af
> klassen strstream.
>
> Jeg opretter objektet på følgende simple måde:
> strstream streng_stream;
> og så vidt jeg ved, bruger strømmen derfor automatisk en dynamisk > > allokeret
> buffer, som jeg selv skal sørge for at deallokere.


Hvor har du denne information fra? Er pointen ikke netop at man skal
slippe for den slags overvejelser?

Mads

Det er meget muligt at det er mig der er galt afmarcheret. Men faktum er at mit program på et halvt minut bruger 400MB hukommelse og det er denne strstream forårsager dette. Da jeg så læste følgende i en Borland C++ header file hjælp-fil:


" strstream::str (member function)
==================================
Declaration:
 char *str();

Remarks:
Returns and freezes the buffer.

You must de-allocate the buffer if it was
dynamic."

Så tænkte jeg at jeg selv skulle de-allokere. str er den funktion jeg bruger til at få indholdet af bufferen ned i en streng (en dårlig metode?). Jeg har prøvet at un-freeze bufferen med freeze(0), men så går mit program i stå. Skal bufferen un-freezes før den kan de-allokeres automatisk?

Den relevante del af mit program ser ud som følger:

for(faktor2=(step_nr*step_len); faktor2<=((step_nr+1)*step_len); faktor2=faktor2+(cl_I)1)
{
strstream faktor_stream, produkt_stream;
faktor_stream << faktor1 << faktor2;
produkt_stream << (faktor1 * faktor2);


if(vampire(faktor_stream.str(), produkt_stream.str()))
{
output_file.open("vampire.txt", ios::out | ios::app);
output_file << faktor1 << " * " << faktor2 << " = " << (faktor1 * faktor2) << endl;
output_file.close();
}
// faktor_stream.freeze(0); Virker mærkeligt nok ikke.
// produkt_stream.freeze(0); -"-
}


Jeg håber ikke, at jeg trætter jer alt for meget med dette umiddelbart trivielle problem.

Med venlig hilsen
Emil Zeuthen
---- -------


_________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *