Re: Memory Management
- From: Michael Carman <mjcarman@xxxxxxxxx>
- Date: Sat, 28 Apr 2007 02:41:01 GMT
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
.
- Follow-Ups:
- Re: Memory Management
- From: Shiraz
- Re: Memory Management
- References:
- Memory Management
- From: Shiraz
- Re: Memory Management
- From: Michael Carman
- Re: Memory Management
- From: Shiraz
- Memory Management
- Prev by Date: Re: finding invalid method names
- Next by Date: Re: finding invalid method names
- Previous by thread: Re: Memory Management
- Next by thread: Re: Memory Management
- Index(es):
Relevant Pages
|
|