GSAK (Geocaching Swiss Army Knife)
Contents - Index

AddStr (function)

AddStr(nBuffer,sAction,[sdata]) : string

Optimized function to concatenate strings. It appears that Delphi is not that flash when it comes to concatenation of long strings with the native + operator when done many times. It appears to be inefficient, slow, and cause severe memory fragmentation.

As a rule of thumb, when adding long strings to the same variable via the native + operand, things start to go South after about 2000 iterations.

The AddStr() function has been introduced to help fix this shortcoming and should be used when building a large string in memory by continually adding other strings to the same variable. 

nBuffer - This is an internal buffer number (1 to 10) for storing the large strings
sAction - The action to communicate with our internal buffer

    * clear - clear the buffer
    * add - add strings to the buffer
    * get - retrieve the full contents of the buffer

sData - Optional and only required when sAction is "add"

The AddStr() function works like this

1. Before use you must "clear" the behind the scenes buffer that accumulates the strings
2. You then just keep adding strings as required
3. Finally, to access the "buffer" of data you must "get" it.

Probably the best way to explain is to see it in action. 
 

timer status=on
$recno = 0

# clear out the internal number 1 buffer and create our "big" variable at the same time.
$big = addstr(1,"clear")

goto position=top
While not($_eol)
$recno = $recno + 1

# this line of code just populates our "internal buffer". $big always returns an empty string here
$big = addstr(1,"add",$d_shortdescription + $d_longdescription + $d_Url)

IF frac($Recno/20) = 0
   ShowStatus msg="Processing record $recno of $_count"
endIf
goto position=next
EndWhile

# Finally we retrieve the data from our "internal buffer" to use in the macro
$big = addstr(1,"get")

Goto Position=Top
timer status=off

 
Alpha List         Category List

Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact