Re: Memory Management



On Apr 27, 9:41 pm, Michael Carman <mjcar...@xxxxxxxxx> wrote:
On 4/27/2007 5:36 PM, Shiraz wrote:



I know I can allocate memory space by using ` $#arr = 999 ` but i am
not sure how much memory it consumes. Basically my goal is to figure
out how to set the max memory a variable can use and how to monitor
when the max has been reached.

'$#arr = 999' will set the size of the array to 1000 elements. That could either
extend or truncate the @arr depending on what length it was beforehand. It
doesn't create a limit, though. Perl will extend the array if (e.g.) you were to
push() another item onto the end.

You can use Devel::Size to find out how much memory a variable is actually
using, but that's independent of the length. An array of 1000 integers would
take less space than an array of 1000 strings. Array elements can be any scalar
value which means you can create an array of hashes of hashes of arrays of...

If you *really* need to continuously monitor the size of an array you could
create a tie() class that used Devel::Size to check the memory consumption every
time you added or modified an element and warn() when it exceeds some threshold.
It would absolutely clobber your performance, though, and I doubt that you
really need to do that. We can probably provide better advice if you tell us
what your real task is.

-mjc



I need to keep a hash of arrays in memory and keep adding things to it
and when the hash has so many things in it that it can cause a perl
out of memory error, i want to prune it. almost like a cache.

.



Relevant Pages

  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Hash table & threading
    ... Hash Tables use more memory, but in almost every case a Hash Table will have ... an array is when the keys are all consecutive integers. ... Another way to lower memory usage is to set the load factor of your hash ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: High Memory Consumption of Classes and Arrays
    ... Only the array itself has overhead. ... memory as a reference type. ... > least consume 40 bytes of memory. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.mfc)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.language)