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

I desperately need to reduce the memory it is using. ... I cannot easily change how it is constructed.

If you cannot change how it is constructed, you cannot reduce the memory that will be used as it is constructed.

You could reduce it after the fact by packing the doubles into a string:

perl -MDevel::Size=total_size -le"@a= map rand(),1..1e6; print total_size \@a; $b=pack'd*', @a; prin +t total_size( $b )" 40000176 8000056

That's a 5 to 1 reduction. It will free up memory for other things if you then undef'd the array, but it usually won't release memory back to the OS.

And the individual elements can be accessed and modified use substr in conjunction with pack & unpack. The penalty is loops run more slowly. PDL would be much quicker.

It would be much better if you could avoid the creation of the array in the first place


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^4: Bizarre Array Size Disparity
by sunmaz (Novice) on May 17, 2012 at 18:15 UTC
    Is it possible, perhaps, to retrieve array slices from an array reference, instead of de-referencing the entire array? Perhaps that would reduce memory consumption.
      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?

        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...
Re^4: Bizarre Array Size Disparity
by sunmaz (Novice) on May 17, 2012 at 18:08 UTC
    Thanks for the advice. I suppose I was hoping for some magical perl use like optimization that would make the array much small. Obviously such a thing doesn't exist.
      I was hoping for some magical perl use like optimization that would make the array much small.

      If you can tie the array before it gets built, you could use Tie::Array::Packed::DoubleNative which would give you the memory reduction of the packed string with the convenience of array index.


      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?

        Interesting, although I don't think I can do that. (I realize I may have no real recourse here)