[fpc-pascal] Move() vs MemCopy()

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Sep 29 16:02:00 CEST 2009


2009/9/29 Florian Klaempfl <florian at freepascal.org>:
>
> Indeed, the serious answer is:
> move handles overlapping memory blocks correctly (so the data might not
> existing anymore at the old location), memcpy doesn't do this and screws
> things up when handling overlapping blocks. This is why e.g. C++ has
> memmove as well which is more expensive than memcpy due to overlap checks.

I thought simple pointer arithmetic would solve the issue of memcpy()?


Anyway, so based on your answer, if we apply the following code (shown
belowe) to FPC, we have the best of both worlds! :-)  MemCopy() does
exactly what Move() does - but without the name confusion. :-)

Could this "alias" procedure be applied somewhere in FPC?  This was
done before - the case of AssignFile() vs Assign()

procedure MemCopy(src, dest: pointer; size: SizeInt);
begin
  Move(src^, dest^, size);
end;



Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list