Re: Streams



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'.


.



Relevant Pages

  • Re: Confusion about I/O Streams
    ... >> that I am definitely dealing with byte streams and that classes for ... > Characters are a higher-level abstraction than bytes. ... >> primitives and Strings to my scratchpad and I'm having trouble finding ... that's fine so far but it is only writing a single String to the ...
    (comp.lang.java.help)
  • Re: TCP/IP Sockets with GNAT.Sockets
    ... the problem is the use of attributes 'Output on arrays which output array bounds before array data. ... and since String is an array, String'Output outputs String bounds before string data. ... you should note that the problem is the same in C: when reading a string from a socket, ... Streams while a Socket package isn't required to give any explanations ...
    (comp.lang.ada)
  • Re: Confusion about I/O Streams
    ... > I have to admit I've never fully understood the different Java I/O streams ... > so I've been reviewing them in the Java Tutorial. ... Characters are a higher-level abstraction than bytes. ... If you've got a String, you can get a bytefrom it using: ...
    (comp.lang.java.help)
  • Re: Best practices for efficient FP string building in CL?
    ... "stupidity" in visualizing sequence operations in terms of recursive ... about efficient, functional string building. ... The nice thing about using streams for functional programmers, ... makes string building look like i/o or message passing ...
    (comp.lang.lisp)
  • Re: UTF-8 practically vs. theoretically in the VFS API
    ... > In short: filenames are byte streams. ... This is the whole benefit to UTF8, ... call multi-byte versions of the standard string functions. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)