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

Vanessa Freudenberg vanessa at codefrau.net
Thu May 21 18:03:16 UTC 2020


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


More information about the Squeak-dev mailing list