Pointer param is nil?

Hey,

I have written following Code, to improve memcpy() Speed and when i debug and jump in the functions it prints me, that the passed start-address is Nil and so the whole Array ?

Can u have a look pls :confused:

class method fast_memcopy(dst: ^void; const src: ^void; const size: UInt32);
begin
  var dst32: ^byte32_align := ^byte32_align(dst);
  var src32: ^byte32_align := ^byte32_align(dst);

  var count32: UInt64 := size div sizeof(byte32_align);
  var rest32: UInt64 := size mod sizeof(byte32_align);

  for x: UInt64 := count32 downto 0 do
  begin
    dst32^ := src32^; 
    inc(dst32);
    inc(src32);
  end;  

  var dst1 : ^Byte := ^Byte(dst32);
  var src1 : ^Byte := ^Byte(src32);

  for x: UInt64  := rest32 downto 0 do
  begin
    dst1^ := src1^; 
    inc(dst1);
    inc(src1);
  end;  
end; 

and i pass a start-adress of dst and src!

writeLn('Start = ' + DateTime.Now.ToString());
   var size := 4096;

   var dst := new array of Double(size * size);
   var src := new array of Double(size * size);
 
   for i : Int32 := 0 to src.Length -1 do
   begin
     src[i] := size * 0.3;
   end;

   fast_memcopy(@dst[0], @src[0], src.Length * sizeOf(Double));

//β€”> src and dst are nil :confused:

They’re not null. But your function had so many bugs that it crashes.


  class method fast_memcopy(dst: ^void; const src: ^void; const size: UInt32);
begin
  var dst32: ^UInt32 := ^UInt32(dst);
  var src32: ^UInt32 := ^UInt32(src); // fix:dst -> src

  var count32: Int64 := size div sizeof(UInt32); // Uint -> int 
  var rest32: Int64 := size mod sizeof(UInt32); // Uint -> int 

  for x: Int64 := count32 -1 downto 0 do // uint ->int ; so we can do -1 here
  begin
    dst32^ := src32^; 
    inc(dst32);
    inc(src32);
  end;  

  var dst1 : ^Byte := ^Byte(dst32);
  var src1 : ^Byte := ^Byte(src32);

  for x: Int64  := rest32 -1 downto 0 do // uint ->int ; so we can do -1 here
  begin
    dst1^ := src1^; 
    inc(dst1);
    inc(src1);
  end;  
1 Like

Thanks, you were right, BUT: There seems to be a bug in the Debugger-Windows, when u hover over the dst, src Parameter u will see, that it Shows Nil! try it.