in reply to Perl Objects, Internal Representation -- How??

Is a perl object stored in its entirety more than once (data, methods and all)?

Just the data. The methods go in the symbol table for the class.

What about hash keys- are they duplicated for each object of the same type?

Yes.

What about hashes (objects of the same type) that have asymmetrical numbers of keys)-- ie., not fully populated?

Doesn't matter. Nothing is shared between objects of the same type except the fact that they are both marked as belonging to the same class. Other than that, they don't even have to the same data type.

What about objects based on hashes versus arrays???

It doesn't matter. All the answers are the same.

  • Comment on Re: Perl Objects, Internal Representation -- How??

Replies are listed 'Best First'.
Re^2: Perl Objects, Internal Representation -- How??
by dave_the_m (Monsignor) on Sep 15, 2006 at 18:07 UTC
    What about hash keys- are they duplicated for each object of the same type?

    Yes.

    Er, no. Hash keys are generally shared across all hashes, as the following shows. Using the same key for lots of objects uses less memory than a different key for each one:
    $ perl588 -e 'push @f, bless { "foo$_",0 } for 100000..999999; system + "ps -flp $$"' F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY +TIME CMD 0 S davem 6040 17980 81 85 0 - 43121 wait 19:05 pts/2 00:0 +0:04 perl5 $ perl588 -e 'push @f, bless { "foo999999",0 } for 100000..999999; sy +stem "ps -flp $$"' F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY +TIME CMD 0 S davem 6045 17980 96 85 0 - 34173 wait 19:06 pts/2 00:0 +0:03 perl5 $

    Dave.

      Good point -- the actual keys of hashes are shared to reduce memory needed. There's a good explanation in PerlGuts Illustrated. This is just standard hash behavior though, not at all related to them being used as objects.