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

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu May 21 21:02:55 UTC 2020


There is a small difference though.
Spur alloc on 8 bytes boundary, while the OS might alloc on 16.
Believe it or not, depending on alignment, accelerated path can differ.
See https://github.com/nicolas-cellier-aka-nice/smallapack/issues/1

Le jeu. 21 mai 2020 à 20:38, Vanessa Freudenberg <vanessa at codefrau.net> a
écrit :

> 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/41a0d80f/attachment.html>


More information about the Squeak-dev mailing list