Riporto questa discussione apparsa nella M.L. ufficiale:
" G'day all:
Linux has "memcopy" and Windows has "MoveMemory". How do I import or
reference memcopy into Gambas? I can see that I should be able to
effect this function using stream Memory Read and Write, but it may
not work as fast? I need to use this many times
Carl. "
" Why do you need to copy memory? You should not, it's dangerous.
--
Benoît Minisini "
" If you have problems to declare memcpy on Gambas, you will very probably
have much more problems with it (unexpected behavior, random crashes, etc).
There very probably is alternative method for this. As Benoit already ask,
why you need it?
Anyway:
Private Extern memcpy(dest As Pointer, src As Pointer, count As Integer) As
Pointer In "libc:6"
Jussi "
" 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 "
" iArray.Data gives the pointer you need.
> Moreover, once you got it, your code may break in the future as soon as
> the internal
> implementation changes.
>
What you mean by this? I'm expecting normal Gambas arrays to be read in
external libraries as c array when passed as iArray.Data. So far this has
worked perfectly. And in my understanding embedded arrays are useful only
if they are part of structure that should be passed to some library.
Changing this would break a lot of things. Have I understood something
incorrectly?
Jussi
Jussi "