Re: slow operation using RetrieveRaw with a TString

Giganews Newsgroups
Subject: Re: slow operation using RetrieveRaw with a TString
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Wed, 18 Nov 2009

"Aur=E9lien" <stop@spam.fr> wrote in message =
news:mn.92f57d9b45d04d74.28031@spam.fr...

> i encounter some long timings using RetrieveRaw with a TStringStream=20
> object, trying to handle mails with large attachements (greater than 1 =

> MB).
>=20
> nevertheless, the network activity seems to be ok, the message is=20
> quickly received : it seems that other (slow) operations occur in the=20
> function after the file has been received.

Do you have the same problem if you use a TMemoryStream instead?  =
RetreiveRaw() has to perform a lot of small writes to the target stream. =
TMemoryStream is more optimized than TStringStream when it comes to =
allocating, reallocating, and accessing the stream's internal memory.

>      AssignFile(Fichier, 'd:\t\mail.txt');
>      FileMode :=3D fmOpenWrite;
>      Rewrite(Fichier);
>      Write(Fichier, Flux.DataString);
>      Flush(Fichier);
>      CloseFile(Fichier);

That is old-style Pascal file I/O.  If you switch to TMemoryStream, you =
gain access to its SaveToFile() method.  If you continue using =
TStringStream, you should at least use VCL-style file I/O instead.  Look =
at the FileCreate() and FileWrite() functions.  Or, use a separate =
TFileStream and call its CopyFrom() method.

--=20
Remy Lebeau (TeamB)

Replies

In response to

slow operation using RetrieveRaw with a TString posted by Aurélien on Wed, 18 Nov 2009