2006/6/7, Alexandre Leclerc <[EMAIL PROTECTED]>:
I asked the question for a string array. I see that we can assign a
string directly to a pchar, but when I SetLength() such an array, do I
have to free the PChar string no more used or is it done
automatically?

var
  a: array of PChar;
begin
  SetLength(a, 4);
  a[0] := 'First pchar line';
  a[1] := 'Second pchar line';
  a[2] := 'Third pchar line';
  a[3] := 'Fourth pchar line';
  SetLength(a,2);
  a[0] := 'Yet another pchar line';
  a[1] := 'At last, a pchar line to finish';
end;

Is the following causing a memory leak? Do I have to SetLength(a, 0)
when I'm completely done with 'a' or is it done automatically?

The following test shows a memory increase for the process each time
it is executed. So I guess that I have a memory leak. An array a PChar
is not a big deal then.

Is there a peculiar reason to use such an array for the DecodeCSVStr
function? (Suggested by Michael, but I send the question to all those
who are interested.)

procedure TMainForm.Button1Click(Sender: TObject);
var
 a: array of PChar;
 i: Integer;
 j: Integer;
begin
 Randomize;
 for i := 0 to 10000 do
 begin
   SetLength(a, Random(1024));
   for j := 0 to High(a) do
     a[j] := 'this is a nice phrase to test teh pchar stuff, yeah,
the phrase is of fixed length, but I''ve no time to waste on this.';
 end;
end;

--
Alexandre Leclerc

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to