Article

From:
To:
Dalija Prasnikar
Subject:
Re: Out of memory Exception when using large StringStream.DataString inD2009
Newsgroup:
embarcadero.public.delphi.rtl

Re: Out of memory Exception when using large StringStream.DataString inD2009

> {quote:title=Dalija Prasnikar wrote:}{quote}
> > {quote:title=Samuel Aeschbacher wrote:}{quote}
> > Hello 
> > I have to read large text-files (> 100 MB) into memory, scan the content and update a database. 
> > 
> > I use TFileStream to read the data, then copying the filestream to a stringstream for better string handling. 
> > If I seek a substring in Stringstream.DataString, I get an "Out-of-memory-Exception" if the size of the Stream exceeds 200 MB (it worked well with a size <= 136 MB and crashed with a size >= 280 MB). 
> > 
> > I'm working with D2009, Windows 7 (32bit and 64bit), Windows-Server 2008 R2 
> > 
> > the filestream (fs) and the stringstream (strstrm) are private class variables of the TDLHI_Main class. 
> > 
> 
> Actually, it would be the best if you skip using any kind of string stream and load
> string directly.
> 
> {code}
> 
> function RawStringLoadFromStream(Stream: TStream; Size: Integer = -1): RawByteString;
> begin
>   if Size = 0 then Result := ''
>   else
>     begin
>       if Size = -1 then Size := Stream.Size - Stream.Position;
>       SetLength(Result, Size);
>       Stream.Read(Pointer(Result)^, Size);
>     end;
> end;
> 
> {code}
> 
> Dalija Prasnikar

Dear Dalija
Thank you very much for resolving the problem with this elegant function.

Kind regards Samuel
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Sun, 06 Oct 2024 02:06:08 UTC
Copyright © 2009-2024
HREF Tools Corp.