Re: Memory Management
- From: Shiraz <shirazk@xxxxxxxxx>
- Date: 27 Apr 2007 20:18:57 -0700
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.
.
- Follow-Ups:
- Re: Memory Management
- From: Michael Carman
- Re: Memory Management
- References:
- Memory Management
- From: Shiraz
- Re: Memory Management
- From: Michael Carman
- Re: Memory Management
- From: Shiraz
- Re: Memory Management
- From: Michael Carman
- Memory Management
- Prev by Date: Re: Cat file a to *.xls files
- Next by Date: Re: Cat file a to *.xls files
- Previous by thread: Re: Memory Management
- Next by thread: Re: Memory Management
- Index(es):
Relevant Pages
|