On 10/25/2009 09:41 PM, Charles Oliver Nutter wrote:

> So I am asking you Rubyists...does this sound like a problem? In the
> 1.8/1.9 stdlib, the only reference to _id2ref is one in drb.rb, which
> could be replaced with a "better way". None of the gems I have
> installed use _id2ref. Originally, weakref.rb used _id2ref, but we
> have a native impl of weakref that uses Java's built-in weakrefs.
> Google code search only brings up about 353 hits for "lang:ruby
> _id2ref", most of them the already-mentioned cases.

Charles, thanks for the elaborate report and request!  I for my part do 
not see an issue with removing _id2ref if a better solution for DRb can 
be devised.

> It's also interesting to note that even maintaining the contract of
> object_id being unique is hard. On the JVM, for example, it is not
> possible to get a unique numeric id or pointer for a given object
> unless you manage a weak map of objects on your own...

I believe there is an alternative solution which comes at the cost of 
the memory overhead for every object: place the id in the instance and 
use a central AtomicLong for "generating" ids.  You also save the 
overhead of map maintenance which would be a central synchronization point.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/