From: Jim Weirich Date: 2004-06-26T01:43:42+09:00 Subject: Re: Is it considered Harmful? Eric Hodel said: > Smalltalk's classes are better factored to handle such occurances. > Ruby's are not. I found the following paragraph about Squeak Smalltalk interesting. Most Smalltalks use an object table to aid in garbage collection. An added benifit of the object table is that swapping two objects is just swapping the pointers in the object table. Squeak doesn't use an object table, so they had to work extra hard to make become: work. Here is the discussion (from http://users.ipa.net/~dwighth/squeak/oopsla_squeak.html): BEGIN QUOTE =================== One more issue remained to be dealt with, and that was support of the become operation without an object table. (The Smalltalk become primitive atomically exchanges the identity of two objects; to Smalltalk code, each object appears to turn into, or "become," the other.) With an object table, the become primitive simply exchanges the contents of two object table entries. Without an object table, it requires a full scan of memory to replace every pointer to one object with a pointer to the other. Since full memory scans are relatively costly, we made two changes. First, we eliminated most uses of become in the Squeak image by changing certain collection classes to store their elements in separate Array objects instead of indexed fields. However, become operations are essential when adding an instance variable to a class with extant instances, as each instance must mutate into a larger object to accommodate the new variable. So, our second change was to restructure the primitive to one that exchanges the identity of many objects at once. This allows all the instances of a class to be mutated in a single pass through memory. The code for this operation uses the same technique and, in fact, the very same code, as that used to rectify pointers after compaction. END QUOTE ===================== -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)