in reply to Are Addresses From refaddr Unique Across Threads?

True inside-objects, your classes are not.

One of the points of inside-out objects is that the references do not point to anything used by the inside-out classes. Only the address is used, and nothing else. Your objects rely on the fact they are hash references, and rely on the key __PACKAGE__. This means you are breaking encapsulation. A subclass can fiddle with the internals (by accident) and you are denying your subclasses any implementation that deviates from being a hashref.

Threads within a process all share the same address space.
Is that true on every platform? Will that always be true, even in a next version or Perl? I don't think Perl gives you that promise; I would hence not rely on it.

But if you're going to store the keys in the object themselves, why bother with the refaddress of which you aren't sure it's going to work? Just use a random number, and if it's already used in %class_records, pick another one. Or use a counter.

BTW, from your code fragment, I don't understand what the role of $class_objects is.

Of course, the easy way is to upgrade to 5.10. Then you can use fieldhashes, and everything will be done for you.

Replies are listed 'Best First'.
Re^2: Are Addresses From refaddr Unique Across Threads?
by ikegami (Patriarch) on Feb 19, 2010 at 21:26 UTC

    Is that true on every platform? Will that always be true, even in a next version or Perl? I don't think Perl gives you that promise; I would hence not rely on it.

    It has to be. You can't have two objects at the same address in the same process.

    Of course, you could have modules that provide the same interface as threads without actually using threads. In fact, such a module already exists.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Are Addresses From refaddr Unique Across Threads?
by BrowserUk (Patriarch) on Feb 15, 2010 at 19:45 UTC

    Threads within a process all share the same address space.

    Is that true on every platform? Will that always be true, even in a next version or Perl?

    I don't think Perl gives you that promise;

    Yes. Yes. And it is not within the auspices of Perl to make or break that promise. They would not be threads otherwise, as that is the very definition of threads.

    I conceed that it is possible that someone could implement something and call it "threads" that would not satisfy that definition, but it would be a very obtuse thing to do.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.