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, then copying the latter to the C heap. Copying *from* the C heap might require explicitly looping over the single bytes. I say "might" because I still cannot find more direct way, as using ByteArray>>replaceFrom:to:with:startingAt: doesn't seem to work. Any suggestion on more effective copy operations? Thanks Raffaello On 22/02/17 15:08, Raffaello Giulietti wrote: > 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, not an object whose content is to be copied > directly. > > > | ea ba | > ea := ExternalAddress gcallocate: 200. > ba := ByteArray new: 100. > ba replaceFrom: 1 to: 50 with: ea startingAt: 51. > > > Am I missing some point? > > > > > On 2017-02-21 17:20, Esteban Lorenzano wrote: >> 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 the starting points and sizes. >> >> cheers, >> Esteban >> >> >>> On 21 Feb 2017, at 17:13, Raffaello Giulietti >>> <raffaello.giulie...@lifeware.ch> wrote: >>> >>> 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-result/UnifiedFFI/UnifiedFFI.pdf >>> >>> >>> Thanks for directing me at relevant docs or examples and sorry in >>> advance if I missed some important point in the docs. >>> >>> RG >>> >>> >> >> > >