Long String Generation

Kevan Hashemi hashemi at brandeis.edu
Mon Feb 15 20:40:25 CET 2010


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.

Yours, Kevan



-- 
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/





More information about the Gpc mailing list