An object has a hash value (self hash). 1. How can I get hold of an object with its hash value? anInstance _ AClassCanCreateInstanceUsingHashValue hash: 2340 It is in the nature of hash codes that they are not unique. There could be many thousands of objects with that hash code. Hash codes are not pointers, they're just a hack to speed up table lookups.
I haven't checked: does Squeak 3.x still use 12-bit hash codes?
2. If I can get hold of an instance, how can I destroy it? Unseemly hacking in the VM aside, you can't. Smalltalk objects can survive anything except the death of (their) universe and insufficient attention. If you stop looking at them, they pine away.
What you _can_ do is hunt down variables holding references to an object and nil them out, whereupon the object will eventually pine away because no-one is interested any more.
What is the application problem you are trying to solve by these means?
"Richard A. O'Keefe" ok@atlas.otago.ac.nz wrote:
An object has a hash value (self hash).
- How can I get hold of an object with its hash value? anInstance _ AClassCanCreateInstanceUsingHashValue hash: 2340
It is in the nature of hash codes that they are not unique. There could be many thousands of objects with that hash code. Hash codes are not pointers, they're just a hack to speed up table lookups.
I haven't checked: does Squeak 3.x still use 12-bit hash codes?
YES! For my type inferencer, which has a few sets way bigger than 2^12, I implement custom hash functions. 4096 is a lot for most purposes, but ocassional cases require more.
(A cool trick would be if the VM offered optional "long identity hashes". Small identity sets ask for regular 12-bit hashes, and large ones ask for the large, optional ones. The same could be done at the image level for regular #hash -- you could have #hashForSize: (or maybe #hashOfSize:), and certain objects can generate better hashes for larger collections. String in particular might benefit!)
Overall, hashing is a funny beast to work with. It works phenomenally well when it works, but you have to get several things right or it can fail horribly! A funny problem I had once involved removing the first element from a set and then adding an arbitrary element to the middle; thus, over time, I had systematically skewed the set's data to towards the end of the set. Doh!
Lex
squeak-dev@lists.squeakfoundation.org