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

Is it possible, perhaps, to retrieve array slices from an array reference, instead of de-referencing the entire array?

You'd have to explain (Show code!) how the array is being populated and used before that question could be answered accurately.


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^6: Bizarre Array Size Disparity
by sunmaz (Novice) on May 17, 2012 at 18:29 UTC
    The population of the array is done from an extrinsic library and returns and array reference. It should be considered an inscrutable process. I have sufficient memory for that. My issue occurs upon dereferencing the array.
    my @unfilteredOutput = @$outputRef; ... my $total_size = total_size(\@unfilteredOutput); print PROGRESS "SIZE OF UNFILTERED OUT FROM INFO FILTER: ".$total_ +size;
    $total_size is too large. I know that isn't much help...sorry...
      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?

        I don't know why this didn't occur to me. Thanks!
        Can I tie and pack the reference directly to further minimize memory usage?