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

Marcel Taeumel marcel.taeumel at hpi.de
Thu May 21 18:29:41 UTC 2020


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 [mailto: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/5f238978/attachment.html>


More information about the Squeak-dev mailing list