flipper has asked for the wisdom of the Perl Monks concerning the following question:

I'm working my way through a heap of debug output I've generated, I was trying to make it easy to track objects by finding things like HTTP::Connection=HASH(0xbef7360) and replacing them with HTTP::Connection=HASH(__FD_37__).

I have found somthing which surprised me - I have other objects which exist at the same time which have the same pseudo-address, but are of a different type eg HTTP::OtherClass=HASH(0xbef7360) - ie 0xbef7360 is in the stringification of two different objects in the same process.

Admittedly there are an awful lot of objects about (thounsands to tens of thousands), but I though this shouldn't happen - was I wrong, or is my program really broken? :-)

Thanks,


Pete

Replies are listed 'Best First'.
Re: Duplicate "addresses" in hashrefs when printing
by almut (Canon) on Jun 09, 2009 at 10:41 UTC
    I have other objects which exist at the same time which have the same pseudo-address

    Are you absolutely sure they exist at the same time? Once an object is destroyed, its associated memory may be recycled...  Or perhaps the object is being reblessed?

    Could you provide a (simplified) sample script that demonstrates the issue?

Re: Duplicate "addresses" in hashrefs when printing
by kyle (Abbot) on Jun 09, 2009 at 12:32 UTC

    My first thought is what almut wrote already. Probably what happened is that you dumped HTTP::Connection=HASH(0xbef7360), it was then destroyed, and the memory was reused to make HTTP::OtherClass=HASH(0xbef7360) (so it has the same address).

    It's also possible to bless an existing object into some other class. In that case, rather than HTTP::Connection=HASH(0xbef7360) being destroyed, it just got reblessed into HTTP::OtherClass somewhere.

    Either way, you wouldn't see HTTP::Connection=HASH(0xbef7360) and HTTP::OtherClass=HASH(0xbef7360) at the same time, only in two separate dumps.

Re: Duplicate "addresses" in hashrefs when printing
by ikegami (Patriarch) on Jun 09, 2009 at 15:33 UTC

    I have found somthing which surprised me - I have other objects which exist at the same time which have the same pseudo-address, but are of a different type eg HTTP::OtherClass=HASH(0xbef7360) - ie 0xbef7360 is in the stringification of two different objects in the same process.

    0xbef7360 is the memory address (within the process's address space) of the referenced object. It's impossible to have two objects (or two anything) at the same memory address at the same time.

    And since the blessing is associated with the underlying variable, not the reference to it, it's not even possible to have to references of different class to the same variable.

    my %hash; my $o1 = bless \%hash, 'C1'; my $o2 = bless \%hash, 'C2'; print "$_\n" for $o1, $o2;
    C2=HASH(0x1829974) C2=HASH(0x1829974)