tcarmeli has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have some script which uses some mildly complex data structures and consumes a lot of memory. I wanted to do some memory usage profiling and came across Devel::DumpSizes.
Since the results seemed very strange, I tried to see what &Devel::Size::size (which is the basic function it uses) gives for simple scalars.
The way I understand it, for scalars the results should be the same as length() returns. Why isn't it so?
I started off with bit-vector style values but also a simple example such as the last one, the variable $five, demonstrates it as well. Acording to Devel::Size it coonsumes 37 bytes (?!) what do I miss here?
#!/usr/bin/perl -w use Devel::Size qw(size total_size); my $packed1=pack("b24",'111100001111000011110000'); my $packed2=pack("b24",'111100000000000011110000'); my $raw='111100001111000011110000'; my $xor=($packed1^$packed2); my $five=5; printf "packed1 %d, %d\n",length($packed1),size($packed1); printf "packed2 %d, %d\n",length($packed2),size($packed2); printf "raw %d, %d\n",length($raw),size($raw); printf "xor %d, %d\n",length($xor),size($xor); printf "five %d, %d\n",length($five),size($five);

Replies are listed 'Best First'.
Re: Help needed on Devel::Size
by Corion (Patriarch) on Mar 05, 2007 at 09:44 UTC

    See PerlGuts Illustrated - a simple scalar isn't that simple - it contains some administrative overhead for refcounting, magic and some other fields.

      Thanks!
      Well, cut me some slack here, I'm originally a HW engineer...
        'slack' =~ s/.//;