[Gambas-user] How to import and/or use Linux function "memcopy"?

Benoît Minisini gambas at ...1...
Sat Jan 25 15:49:14 CET 2014


Le 25/01/2014 15:12, Carl Nilsson a écrit :
> Good evening Benoit:
> Actually, it is the C function memmove that I
> want to use.  I will be using it all the time to
> shuffle array elements along, like a shift
> register in data filtering.  The Windows function
> CopyMemory  is very fast and much more efficient
> than using do loops in VB6.  It is also very
> useful in handling serial input byte data which
> comes in varying size packets.  I have been using
> the Win kernel CopyMemory for years in VB6
> without problems and I wish to implement similar
> functionality in the port to Gambas.  This
> evening I have got as far as being able to run
> memmove in Gambas, but not yet correctly.  I'm
> still struggling a bit with pointers.  It seems I
> cannot use VarPtr on a (1-D) integer array at a
> particular element number of a linear, say,
> integer array like VarPtr(iArray[18]).  So I have
> got as far as trying iPtr = VarPtr(iArray) +  72
> (for that example) without success.  I have
> assumed my iPtr (declared as a Pointer) is an
> integer value that increases by 4 for each
> integer element, but I could be off the
> track.  Being "dangerous" does not unduly concern
> me - my computer won't blow up! I just need to
> move blocks of data back and forth quickly!
> Carl
>
>

If you just need to move a number of consecutive elements from one array 
to another array of the same type, I can add a method for that.

Something like: AnArray.CopyTo(AnotherArray, DestinationIndex, 
SourceIndex, Count)

That method will spend a little time to check its arguments so that you 
don't crash everything.

It will be far more reliable than trying to deal with pointers when you 
don't know how exactly things are implemented. Moreover, once you got 
it, your code may break in the future as soon as the internal 
implementation changes.

-- 
Benoît Minisini




More information about the User mailing list