Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical


by bart (Canon)
on Jul 18, 2004 at 10:29 UTC ( #375360=note: print w/ replies, xml ) Need Help??

in reply to Re: Why is a hash the default "object" in oo perl?

I use inside-out objects for my database persistence module, because it also helps with synchronization.
I'm intrigued. Can you show us some code?

One more thing:

So instead of using the pointer address as the key to the instance data hash, I use the primary key from the database. This is a big win, because there may be many objects instantiated that correspond to the same row in the database.
in contrast with:
So be sure to add:
sub DESTROY { delete $agedata{+shift}; }
.. and clear out all instance data hashes.
Surely that will pose a problem if you can have several objects pointing to the same hash item? What do you do about that, do you keep a reference count yourself?

And I've been pondering if weak references could be used, to do the cleanup automatically for you. I just don't see how...

Comment on Re^2: Why is a hash the default "object" in oo perl?
Download Code
by nothingmuch (Priest) on Jul 18, 2004 at 12:56 UTC
    I once had an LRU cache purge itself using DESTROY on linked list nodes, that knew how to delete themselves from a hash. The only way I found was to tell the nodes which lookup key they had.

    Retrospectively i would have the hash point to dually linked list nodes, which knew their keys too. Then each access would not create a new node, but rather bubble it up. That way the linked list doesn't grow.

    To purge either implementation, you just pop off the linked list, and let the ref count reach zero.

    zz zZ Z Z #!perl
by blokhead (Monsignor) on Jul 18, 2004 at 17:02 UTC


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://375360]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-12-27 01:11 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (176 votes), past polls