[squeak-dev] FFI | ByteArrays: Authentic or Fabricated? :-)

Vanessa Freudenberg vanessa at codefrau.net
Thu May 21 18:38:25 UTC 2020


The old object memory did not have pinning. So if you needed an unchanging
address, you had to allocate it externally.

With Spur’s pinned objects there is less need for external allocations,
true.

However, there is more risk of corrupting your object memory if the
ByteArray is not large enough. Externally allocated memory is a little
safer in that regard.

Also, you may have to think more about what happens after image reload.
Then again, that’s tricky with FFI either way.

- Vanessa -

On Thu, May 21, 2020 at 11:30 Marcel Taeumel <marcel.taeumel at hpi.de> wrote:

> Hi Vanessa!
>
> > You just need to make a ByteArray that is large enough to hold the
> struct. Passing that to FFI will pass a pointer to the first byte of the
> ByteArray. The API call would fill the ByteArray. So it should Just Work.
>
> Ah, I thought so. But I did not verify it by looking at the FFI sources.
> :-)
>
> So, is there any need for #newExternal and #free?
>
> Best,
> Marcel
>
> Am 21.05.2020 20:03:40 schrieb Vanessa Freudenberg <vanessa at codefrau.net>:
>
> On Thu 21. May 2020 at 00:30, Marcel Taeumel <marcel.taeumel at hpi.de>
> wrote:
>
>>
>>
>> Latest thing -- that's why this question about ByteArrays -- was how to
>> re-think this code:
>>
>> MyStruct foo;
>> someFunctionFillsMyStruct(&foo);
>>
>> Into this code:
>>
>> foo := MyStruct new. "handle is ByteArray"
>> self apiSomeFunctionFillsMyStruct: foo.
>>
>> Meaning, what whould be on the stack in C, can conveniently be hold in
>> Squeak's object memory to be shared across Squeak processes and
>> applications.
>>
>
> I was under the impression that is exactly how it works.
>
> You just need to make a ByteArray that is large enough to hold the struct.
> Passing that to FFI will pass a pointer to the first byte of the ByteArray.
> The API call would fill the ByteArray. So it should Just Work.
>
> - Vanessa -
>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200521/1b260e76/attachment.html>


More information about the Squeak-dev mailing list