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

Florian Klaempfl florian at freepascal.org
Tue Sep 29 16:16:50 CEST 2009


Graeme Geldenhuys schrieb:
> 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. :-)

It does not. MemCopy is simpler and because of the missing overlapping
checks, it as faster and it can be often inlined.

> 
> 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/
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 




More information about the fpc-pascal mailing list