Accessing an oop

David T. Lewis lewis at mail.msen.com
Tue Jun 22 23:52:47 UTC 1999


On Tue, Jun 22, 1999 at 06:48:54PM -0400, Stephen Pair wrote:
> I just wanted a quick and easy way of generating nicely distributed numbers
> to keep track of some externally referenced objects and give the external
> system a handle to referenced the objects.
> 
> I was think maybe doing something like:
> 
> (oop * 65536) + oop
> 
> where oop is the short oop given by #asOop...I would then simply increment
> this number until I find a slot in event of a collision.
> 
> Is there a better way?
> 
> - Stephen
>

Check "SystemDictionary>>RegisterExternalObject:". This is for keeping
track of objects (typically Semaphores) which are used by external
programs or primitives. If I understand correctly, the garbage collector
will avoid moving a registered object, and the address of the object
as seen by an external program remains valid until the object is explicitly
unregistered, or until the next restart of the Smalltalk image.

There are a number of methods, such as "Interpreter>>ArrayValueOf:",
which provide the addresses of the interesting parts of objects.
When translated to C, these addresses can be directly accessed in
pluggable primitives.  There is no need to know the oop of the object
itself.

By the way, I think that the tricky part of the problem is keeping the
Smalltalk objects from moving around on you while you are referencing
them in your external program. Just getting the oop, or finding the
virtual address of the object in memory, won't do the trick.





More information about the Squeak-dev mailing list