Re: Streams
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 12:05:15 -0500
Maarten Wiltink wrote:
You're probably being bitten by the stream reallocating the string it uses for storage every time you append to it. A quick glance at the code seems to suggest that there's no easy way to prevent that. Every Write() truncates the contents so you can't pre-allocate the way you can with TStringList. You'd have to write your own derived class that doesn't truncate; it should be very little work.
A search would probably turn up a ready-made TStringBuilder class for Delphi, inspired by .Net's StringBuilder class. It's designed especially for constructing strings incrementally without excessive memory re-allocations.
Nonetheless, J French had the right idea: send the data directly to the compression stream and skip the intermediate storage -- the array copy, the string list, etc. The trick is finding a compression stream that supports that. The free JCL has such a class, TJclZLibCompressStream.
var
FileStream, CompressionStream: TStream;
begin
FileStream := TFileStream.Create(...);
try
CompressionStream := TJclZLibCompressStream.Create(FileStream);
try
// Write data directly to this stream. It will be compressed and
// and piped through to the output file.
finally
CompressionStream.Free;
end;
finally
FileStream.Free;
end;
end;-- Rob .
- References:
- Streams
- From: Richard
- Re: Streams
- From: Nicholas Sherlock
- Re: Streams
- From: Richard
- Re: Streams
- From: J French
- Re: Streams
- From: Richard
- Re: Streams
- From: Maarten Wiltink
- Streams
- Prev by Date: Re: Streams
- Next by Date: Re: Window being cut off (in spite of scaled=false)
- Previous by thread: Re: Streams
- Next by thread: Re: Streams
- Index(es):