Re: Faster way of making long string?
- From: "Bruce Roberts" <ber@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 17:19:20 -0400
"Ian Hinson" <pparagon@xxxxxxxxxxxxxx> wrote in message
news:xyKae.22330$5F3.1324@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I want to make a string of numbers from an integer list.
> The code I'm using is pretty simple solution.
As others have mentioned,
a) unless you are processing an awful lot of integers or doing it a huge
number of times the impact on your program of a better algorithm is likely
marginal, and
b) simply reducing the number of intermediate string variables involved
is going to produce the largest time savings.
Below is a solution that should be relatively quick. It uses a dynamic array
of integer, but can be easily modified for other data structures.
type
tIntList = array of integer;
function IntListToString (iList : tIntList) : string;
var p, dst : pChar; lth, ix : integer;
begin
lth := Length (iList) * 12 + 1; // largest possible size
p := StrAlloc (lth);
try
dst := p;
for ix := 0 to High (iList) do
inc (dst, FormatBuf (dst^, lth, '%d,', 3, [iList [ix]]));
dec (dst); // get rid of trailing comma
dst^ := #0;
result := p;
finally
StrDispose (p);
end;
end;
.
- References:
- Faster way of making long string?
- From: Ian Hinson
- Faster way of making long string?
- Prev by Date: Re: Faster way of making long string?
- Next by Date: Re: Faster way of making long string?
- Previous by thread: Re: Faster way of making long string?
- Next by thread: Inactive shutdown service
- Index(es):
Relevant Pages
|