Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread stepharong
What about an existing library that I don't want or cannot modify? Really, I agree that this is a problem that Pharo has to solve. Yes we all agree on that. For the record, esteban rewrote from Scratch an FFI and it was not in our plans due to the change in Spur. We would have preferred

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread raffaello . giulietti
On 23/02/17 19:26, Esteban Lorenzano wrote: > >> On 23 Feb 2017, at 19:21, raffaello.giulie...@lifeware.ch >> wrote: >> >> On 23/02/17 19:17, Esteban Lorenzano wrote: >>> On 23 Feb 2017, at 19:11, raffaello.giulie...@lifeware.ch

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread Esteban Lorenzano
> On 23 Feb 2017, at 19:21, raffaello.giulie...@lifeware.ch wrote: > > On 23/02/17 19:17, Esteban Lorenzano wrote: >> >>> On 23 Feb 2017, at 19:11, raffaello.giulie...@lifeware.ch wrote: >>> >>> Hi Esteban, >>> >>> yes, I already looked at LibC's memcpy, but that doesn't help in case >>> you n

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread raffaello . giulietti
On 23/02/17 19:17, Esteban Lorenzano wrote: > >> On 23 Feb 2017, at 19:11, raffaello.giulie...@lifeware.ch wrote: >> >> Hi Esteban, >> >> yes, I already looked at LibC's memcpy, but that doesn't help in case >> you need to copy a *portion* of the ByteArray that does not start at >> index 1. While

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread Esteban Lorenzano
> On 23 Feb 2017, at 19:11, raffaello.giulie...@lifeware.ch wrote: > > Hi Esteban, > > yes, I already looked at LibC's memcpy, but that doesn't help in case > you need to copy a *portion* of the ByteArray that does not start at > index 1. While one can do pointer arithmetic on ExternalAddress, t

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread raffaello . giulietti
Hi Esteban, yes, I already looked at LibC's memcpy, but that doesn't help in case you need to copy a *portion* of the ByteArray that does not start at index 1. While one can do pointer arithmetic on ExternalAddress, this does not, of course, apply to ByteArray. To sum up, I think Pharo 5 currentl

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread stepharong
Hi rafaello once you find the solution can you do a pull request on the UFFI doc? Your question is important we should improve the documentation. tx Stf Hi, browsing through ByteArray's and ExternalAddress's code, I'm getting the impression that copying *portions* of ByteArrays from/to the C

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread Esteban Lorenzano
Sorry, I forgot to answer and now I'm in movement. Look in LibC memcpy method (is not called exactly like that) and his uses. That's the faster you can move things inside the image. And remember: an EA is a pointer and a ByteArray is an array who will be passed as pointer too. Esteban > On 2

Re: [Pharo-users] UFFI and ByteArray

2017-02-23 Thread raffaello . giulietti
Hi, browsing through ByteArray's and ExternalAddress's code, I'm getting the impression that copying *portions* of ByteArrays from/to the C heap can be quite costly. Copying *to* the C heap sometimes requires first copying the portion of the ByteArray into a newly instantiated temporary ByteArray

Re: [Pharo-users] UFFI and ByteArray

2017-02-22 Thread Raffaello Giulietti
Hi Esteban, not sure I'm understanding your snippet correctly. Below is my try. It throws a SubscriptOutOfBounds exception in the last line. The reason is that the implementation of ByteArray replaceFrom:to:with:startingAt: does not consider that ea is meant to be a pointer to a C byte array,

Re: [Pharo-users] UFFI and ByteArray

2017-02-21 Thread Esteban Lorenzano
usually, something more or less like this: sourceByteArrayOrExternalAddress := … some ... destEnternalAddressOrByteArray replaceFrom: 1 to: sourceByteArrayOrExternalAddress size with: sourceByteArrayOrExternalAddress startingAt: 1 and or course you can play with

[Pharo-users] UFFI and ByteArray

2017-02-21 Thread Raffaello Giulietti
Hi, I'm having a hard time finding documentation on how to copy a portion of a ByteArray to/from another portion of a heap allocated C byte array with UFFI. My current reference is https://ci.inria.fr/pharo-contribution/view/Books/job/PharoBookWorkInProgress/lastSuccessfulBuild/artifact/book