jonT
4/16/2006 11:10:00 PM
>John, it's very difficult to determine the size of an object in Ruby.
>The question is how far do you travel the object graph started at the
>instance you want to determine the size for? It's easy if your instance
>just references basic types (e.g. numbers, true, false...) but it gets
>complicated even for String because several instances may share memory.
>Trying to determine the size is slow, inaccurate and error prone.
Ah! I wasn't aware that Ruby did that :( (though it is rather
intelligent...). My data structure is purely hierarchical in nature, so
I had been hopeful.
>Using the collection's size is the easiest and probably most efficient
>approach here.
And it's the approach I think I'll have to take.
>> I had a look at Weak Reference but it's not really appropriate: the max
>> size would be based on the user's system rather than my chosen limit.
>What's wrong with that?
I've written a Ruby shell (much better than Irb) that stores a complete
history of executions (inputs and result). That history is stored
across
sessions using mashaling (now you see why I want a queue with limited
size)...
[Of course the downer of my approach is that you can define a class /
method
in one session, the marshaling won't bring it back. Worst still if you
had
an instance of it.Still haven't find an elegant solution to this]
Anyway, using weak references:
(1) doesn't give me too much control, e.g. to ensure that history
entries
are deleted oldest first.
(2) means that I can't choose to set the history to an arbitrary size.
Cheers,
jonT