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'

Replies are listed 'Best First'.
Re^2: Perl object memory overhead
by LanX (Saint) on Feb 10, 2021 at 23:54 UTC
    > system "ps -o vsz= -p $$";

    do you happen to know how to best replicate this on windows?

    FWIW: I was experimenting with something like

    PS D:\tmp\pm> perl -e'print `powershell (ps -id $$).pm`' 1564672

    not sure if there is a better way (or if it's fully equivalent).

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      Sadly (or not :-) no. I don't do Windows if I can avoid it, only on specific points if needed. In which cases almost always perl provides me longbow and sword to attack the enemy's bugs, e.g. patching binaries inplace or such :P

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