Kevan Hashemi wrote:
I get a factor of 30 decrease in execution time while making a string out of 10,000 integers when using the following routine to append to append each new interger string to the existing string.
procedure string_append(var s,p:string);
var i,num_to_add,old_length:integer;
begin old_length:=length(s); if (s.capacity-old_length<length(p)) then begin num_to_add:=s.capacity-old_length; setlength(s,s.capacity); end else begin num_to_add:=length(p); setlength(s,old_length+length(p)); end; for i:=1 to num_to_add do s[old_length+i]:=p[i]; end;
So, SetLength is all I needed.
Or simply (this routine is also defined in stringutils.pas which comes which GPC): procedure AppendStr (var s: String; const Source: String); begin Insert (Source, s, Length (s) + 1) end; Frank -- Frank Heckenbach, f.heckenbach@fh-soft.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8