external objects

Craig Latta Craig.Latta at NetJam.ORG
Tue Mar 30 00:22:49 UTC 1999


Hi Marcel--

> I've looked at the code a little bit, and was intrigued by the  
> references to EXTERNAL objects, but not exactly sure how this works  
> or even if it really is what I think it is, a way of referencing user  
> settable Squeak objects from the outside.  In fact, I would *love*  
> to see a small architectural overview if that is possible, because it  
> looks like there's a lot of really interesting stuff there.

	Sure... You can register any object in the "external objects array" with SystemDictionary>>registerExternalObject:. That method answers an integer. You can use that number to access the object in virtual machine code, because the exteral objects array is an element in the "special objects array". The special objects array is a global virtual machine variable called specialObjectsOop.

	I don't think there is generic external object access support in the virtual machine, but we could easily define a macro for it. It would be something like:

#define externalObjectAt(index) longAt(((((char *) (longAt(((((char *) specialObjectsOop)) + 4) + (38 << 2))))) + 4) + ((index - 1) << 2));

All of the external objects in my networking framework happen to be semaphores. There's already a convenient mechanism for signalling such semaphores from the virtual machine: synchronizedSignalSemaphoreWithIndex(). The parameter is the external object index of the desired semaphore.

	When you're finished using an external object, you unregister it with SystemDictionary>>unregisterExternalObject:. In my networking framework, I do this when external resources are closed. It would be nicer if the unregistering happened via finalization. There's no major penalty for not unregistering, just a slow memory leak. Even nicer than using "external objects" at all would be fixed-address objects. That's what I used in my previous implementation of the networking framework. The basic issue here is that the addresses of Smalltalk objects being used by C libraries shouldn't change (e.g., by the garbage collector).


	I hope that makes sense,

-C


--
Craig Latta
composer and computer scientist
craig.latta at netjam.org
www.netjam.org
latta at interval.com
Smalltalkers do: [:it | All with: Class, (And love: it)]





More information about the Squeak-dev mailing list