[fpc-pascal]How to copy a lot of data?

Judison jueca at brturbo.com
Wed Dec 4 05:04:48 CET 2002


Hi all,

I have a C function like this:

void GetData(long x; unsigned char **data; unsigned long *rsize);
procedure GetData(x: longint; data: PPbyte; rsize: Pdword);

that returns the data I want (based on x), and rsize that indicate the size of data (in 4 bytes units)
and, after I need to free the data,

void FreeData(unsigned char *data);
procedure FreeData(data: PByte);

I need to make a Pascal procedure, to get this Data, and must be like this:

procedure MyGetData(x: integer; var data; var rsize: integer);
var
  lData: Pointer;
begin
  GetData(x, @ldata, @rsize);
  {copy lData^ to Data, (rsize div 4) bytes}
  FreeData(lData);
end;

What is the correct way?

A)
  Data := lData^; // this will copy rsize * 4 bytes?

B)
  for I := 0 to NItems -1 do
    PInteger(@Data)[I] := PInteger(lData)[I];

C) none of above ;)


If you ask "why?" it's because I need to call:

GetMyData(1, MyRecord, rsize);
GetMyData(2, MyArray, rsize);
GetMyData(3, MyInteger, rsize);

TIA
Your friend,
Judison




More information about the fpc-pascal mailing list