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

Mail #14588

Back to main page of archive

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

From: Frank Heckenbach
Subject: Long String Generation
Date: 15 Feb 2010, 22:36:09

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

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


Replies

Author Subject Date
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
Kevan Hashemi Long String Generation 15 Feb 2010, 14:40:25

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