Re: Memory Management



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
.



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: 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)
  • Re: not enough storage... error using GetRows
    ... > array only contained ~150,000 rows. ... It took 19 minutes for GetRows to return (db ... and the prog had consumed 200MB of memory. ... The first one allocates some 180MB, the next two only allocate about 47MB ...
    (microsoft.public.vb.database.ado)