Article

From:
To:
Samuel Aeschbacher
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

Hi,

> function TDLHI_Main.ImportKompendium(var MsgList: TListBox; var PrgrssBar: TProgressBar; FileName : string): string;
> var
>    i : integer;
> begin
>    Result := '';
>    fs := TFileStream.Create(FileName, fmOpenRead + fmShareDenyWrite);
>    strstrm := TStringStream.Create('');
>    strstrm.CopyFrom(fs, fs.Size);
>    fs.Free;
>    i := pos ('<OK_ERROR>', strstrm.DataString); *// ==>  And on the this line, I get the out-of-memory-exception!*
>
> It's interesting, to get the exception on the "pos"-Statement and not as I expected on the copying of the stream.

In Delphi 2007 you get no exception because there you only reference the 
string whereas in the unicode version (delphi 2009 and up) the things 
got complicated and they had to copy the string using the
right encoding (I guess due to the byte oriented streaming mechanisms
and unicode characters) thus it may happen that you need double the 
memory than before! And since many larger continous portions of memory
are not available that often it will cause the out of memory exception

kind regards    Mike
>
> In D2007, it worked well; in D2009 I get this error on the mentioned Windows-platforms (I didn't try to run it on other windows-versions)
>
> Thx for all hints.
> Samuel
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Thu, 21 Nov 2024 21:00:49 UTC
Copyright © 2009-2024
HREF Tools Corp.