FFI and complex data structures

Martin Kuball MartinKuball at web.de
Sun Apr 10 20:44:06 UTC 2005


Am Sunday 10 April 2005 13:01 schrieb Andreas Raab:
> Martin Kuball wrote:
> >  decodeStructure bitstream: (ExternalData fromHandle:
> > aFrameBuffer type: ExternalType byte asPointerType).
> >
> > This triggers the error: Only external addresses can be stored.
> > So Is this just impossible? Do I have to write a real plugin?
>
> If aFrameBuffer is a ByteArray (as I suspect) this will fail since
> the FFI will not allow you store addresses of objects living inside
> the Squeak object memory. Those are *movable* and storing the
> address for some C function call is meaningless - the Squeak
> garbage collector might have long moved this object away from this
> address and you'd start to overwrite random pieces of Squeak
> memory.
>
> You need to create the byte array in external memory say:
>
>  pointer := ExternalAddress allocate: aFrameBuffer size.
>  decodeStructure bitstream:  (ExternalData
>    fromHandle: pointer
>    type: ExternalType byte asPointerType).
>

Thanks for the answer. By the way, wouldn't it be nice to have ffi 
primtives that can retrive and store a ByteArray from external memory 
in one go? Or is it already there and I just don't see it?

Martin



More information about the Squeak-dev mailing list