in reply to Re^6: Bizarre Array Size Disparity
in thread Bizarre Array Size Disparity

My issue occurs upon dereferencing the array. my @unfilteredOutput = @$outputRef;

That not (just) dereferencing the array, it is copying it. Effectively doubling your memory usage. So don't do that.

Anything you can do with @unfilteredOutput, you can do using $outputRef (using a slightly different syntax), without having to copy it first.

For example, you might iterate the elements of @unfilteredOutput like this:

$_ += $somevalue for @unfilteredOutput;

You could do the same thing without having duplicated the memory using:

$outputRef->[ $_ ] += $someValue for 0 .. $#{ $outputRef };

And for your example, you can do:

my $total_size = total_size( $outputRef );

Which will give you the same number, but will avoid having to duplicate it all first.

It seems like you need to read perldsc.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^8: Bizarre Array Size Disparity
by sunmaz (Novice) on May 17, 2012 at 19:00 UTC
    I don't know why this didn't occur to me. Thanks!
Re^8: Bizarre Array Size Disparity
by sunmaz (Novice) on May 17, 2012 at 19:04 UTC
    Can I tie and pack the reference directly to further minimize memory usage?
      Can I tie and pack the reference directly to further minimize memory usage?

      I don't know what you mean by that?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I mean can I somehow use the tie functionality you mentioned to tie the array that is referenced after it has already been created. Is what I did, with the array de-referencing and duplication not idiomatic? Do most people not do it that way?