GNU Pascal Homepage - gpc - gpc-announce - gpc-de - gpc-doc
Diese Seite auf deutsch

Mail #14587

Back to main page of archive

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  

From: Kevan Hashemi
Subject: Long String Generation
Date: 15 Feb 2010, 14:40:25

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

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  


Replies

Author Subject Date
Frank Heckenbach Long String Generation 15 Feb 2010, 22:36:09
Kevan Hashemi Long String Generation 15 Feb 2010, 18:02:50

In reply to

Author Subject Date
Kevan Hashemi Long String Generation 15 Feb 2010, 12:25:50
Maurice Lombardi Long String Generation 15 Feb 2010, 20:01:35

Back to main page of archive


Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.

Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.


This page was created by Crystal 0.999 (Linux 2.4.27/i686).