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

Carl Nilsson nilsson at ...1979...
Sun Jan 26 02:48:47 CET 2014


Benoit:
That would indeed be most helpful. A point about my particular uses.
The nice thing about the CopyMemory function in 
Windows and the memmove in Linux (as I undersand 
it) is that you can copy a simple array to itself 
with the indices shifted - left or right.  For 
example, treating the array as a "stack", I can 
continually update the array by shifting all the 
values one place to the left, thus discarding the 
first and adding a new value to the last (highest 
indice).  That way I can keep a current "last 20 
values" say, and also keep a current sum (for an 
adequate time) by just subtracting the old first 
value and adding the new last one.  That's one 
use.  Just how these functions implement that I 
am unsure, but the effect is a pseudo copy to 
some intermediate array and then a second copy 
back to the original.   This pseudo array is transparent to the user.
Another use is to make space in front of an array 
in which to add an older array segment.  I use 
this in dealing with "remainders" from previous 
serial port inputs.  I don't always know what to 
expect in the input stream, so I may have some 
leftovers I wish to add to the start of a 
subsequent input.  The resize method allows me to 
make room, then shift the later segment to the 
right of the input array to make room for the earlier in front.
Carl
(snip)

>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
>

Carl S Nilsson
137 Gordons Hill Road
Lindisfarne, Tas.
Australia 7015 


More information about the User mailing list