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.
Here the code:
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 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