Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Perl object memory overhead

by shmem (Canon)
on Mar 27, 2014 at 23:21 UTC ( #1080023=note: print w/replies, xml ) Need Help??

in reply to Perl object memory overhead

There's no difference, since an allocated hash is already set up for being blessed.

push @l,{} for 1..3e7; # allocate 3 mill. anon hashes system "ps -o vsz= -p $$"; # get memory usage of process $_ = bless $_ for @l; # bless each hash into 'main' system "ps -o vsz= -p $$"; # again get memory usage __END__ 2650968 2650968

which shows: making an anonymous hash into an object means blessing it into a namespace. That operation signifies no overhead as far as memory is concerned, since the namespace bits are already allocated in the first place.

update: added comments

update: AnomalousMonk correctly noted that 3e7 for 3 millions is wrong by an order of magnitude. Who else noticed? ;)

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2016-10-22 20:29 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (297 votes). Check out past polls.