Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Memory usage double expected

by Discipulus (Canon)
on Oct 27, 2022 at 12:09 UTC ( [id://11147743]=note: print w/replies, xml ) Need Help??


in reply to Memory usage double expected

Hello,

what I see is nonsense to me

This is perl 5, version 26, subversion 0 (v5.26.0) built for MSWin32-x64-multi-thread

With your program (little modification to not watch the task manager) I see it doubled

use strict; use Devel::Size qw(total_size); my $x = 'a' x (2**30); print "Devel::Size = ".human(total_size($x)). +"\n"; open my $cmd, qq(tasklist /NH /FI "PID eq $$"|) or die; while (<$cmd>){ print qq(tasklist PID $$ = $1\n) if /(\S+\s\w{1,2}$)/} sub human{ my $size = shift; my @order= qw/Tb Gb Mb Kb byte/; if($size<1024){return"$size byte"} while ($size >= 1024){$size=$size/1024;pop @order;} return sprintf("%4.2f %2s", $size, (pop @order)); } __END__ Devel::Size = 1.00 Gb tasklist PID 37288 = 2.104.612 K

But with this version of mine I see what everyone is expecting to:

use strict; use warnings; use Devel::Size qw(total_size); my $x; foreach my $order ( qw(20 24 30 32) ){ $x = 'a' x ( 2 ** $order ); print "\n\nsize of scalar 2**$order\n"; print "Devel::Size = ".human(total_size($ +x))."\n"; open my $cmd, qq(tasklist /NH /FI "PID eq $$"|) or die; while (<$cmd>){ print qq(tasklist PID $$ = $1\n) if /(\S+\s\w{1,2} +$)/} } sub human{ my $size = shift; my @order= qw/Tb Gb Mb Kb byte/; if($size<1024){return"$size byte"} while ($size >= 1024){$size=$size/1024;pop @order;} return sprintf("%4.2f %2s", $size, (pop @order)); } __END__ size of scalar 2**20 Devel::Size = 1.00 Mb tasklist PID 19660 = 8.452 K size of scalar 2**24 Devel::Size = 16.00 Mb tasklist PID 19660 = 23.820 K size of scalar 2**30 Devel::Size = 1.00 Gb tasklist PID 19660 = 1.056.012 K size of scalar 2**32 Devel::Size = 4.00 Gb tasklist PID 19660 = 4.201.748 K

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found