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.

In reply to Re: Memory usage double expected by Discipulus
in thread Memory usage double expected by sectokia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.