[FFI] Pointer arithmetic impossible on ByteArray?
andreas.raab at gmx.de
Sat May 20 01:03:43 UTC 2006
nicolas cellier wrote:
> Le Samedi 20 Mai 2006 02:30, Andreas Raab a écrit :
>> Not a chance. The "base address" of an object isn't constant; the object
>> will be moved by a GC and therefore you simply can't guarantee that "foo
>> baseAddress" is a meaningful value for any period of time other than in
>> the primitive call itself (even the return from the primitive could
>> cause a process switch, which could cause GC somewhere, which could move
>> the object, which invalidates the base address).
>> - Andreas
> Of course, i want it in a primitive to avoid this kind of problem.
But even if it's in a primitive, it's no longer immune from GC when you
return from it. So you can neither return "foo baseAddress" or "foo
baseAddress+X" from a primitive in a meaningful way. You'd have to do
the pointer calculation and the call from the same primitive at which
point you're in plugin (and not FFI) land. And yes, in a plugin you can
do that just fine.
> Is a plugin immune to that kind of moving GC ?
No, of course not. You can't keep references to objects across primitive
calls for example. Inside primitive calls it depends on what the
primitive does - various operations (like allocation) may cause GC and
an oop you referred to before the GC will be no longer valid after it
unless you explicitly remap it.
More information about the Squeak-dev