Re: Streams
- From: erewhon@xxxxxxxxxx (J French)
- Date: Wed, 31 Aug 2005 08:02:15 +0000 (UTC)
On Tue, 30 Aug 2005 07:51:59 -0500, "Richard" <REMOVE
AT-DOTrwskinnerAT@awesomenetDOTnet> wrote:
>
>A little Test Program show below, once it gets over 1000 lines, it slows WAY
>down. String Streams do not seem to be the way to handle this, do they? It
>will process about 1000 strings in 0 seconds, 2000 strings takes 20 seconds.
>I have to do 43200 lines.
As the others pointed out, I really did mean write directly into the
compression stream and skip making an intermediary 'thing' entirely.
However, you've raised a couple of interesting points.
When concatenating small strings to produce one big one, then the
trick is to pre-calculate the length of the big string
- do SetLength once
- then 'insert' the small strings into the large string
That prevents the creation of thousands of strings as the big string
grows
- pre-calculation is lightning fast
- string creation is relatively slow - especially lots of them
- creating a 'growing' string leads to massive memory fragmentation
This is what I use for string insertion
- it will never grow a string - by design
- one could use Move() - but ... well
{ ##############################################
MidSet( L, 4, S )
}
Procedure MidSet( Var BigStr:String; Const HStart:Integer ; Const
SmallStr : String ) ;
Var
L9, BL, SL, L, Start : Integer ;
Begin
BL := Length( BigStr ) ;
SL := Length( SmallStr ) ;
Start := HStart - 1 ; { adjust start }
L := Min( SL, BL - Start ) ;
For L9 := 1 To L Do
BigStr[ L9 + Start ] := SmallStr[ L9 ] ;
End; {MidSet}
Your use of the TStringStream was interesting
- its behaviour is a bit odd, Streams do not normally truncate after a
WriteString ( or Write )
I've never spotted that before
You could have used a TMemoryStream, if you set its size to a
pre-calculated value it would be very fast, but personally if I want a
string then I prefer to use string routines rather than some other
object as an intermediate 'helper'.
.
- References:
- Streams
- From: Richard
- Re: Streams
- From: Nicholas Sherlock
- Re: Streams
- From: Richard
- Re: Streams
- From: J French
- Re: Streams
- From: Richard
- Streams
- Prev by Date: Re: Window being cut off (in spite of scaled=false)
- Next by Date: Re: J. French - See this ?
- Previous by thread: Re: Streams
- Next by thread: Re: Streams
- Index(es):
Relevant Pages
|