Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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'


Comment on Re: Perl object memory overhead
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2015-07-28 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls