[Pdx-pm] Measuring memory consumption of scalars

Eric Wilhelm ewilhelm at sbcglobal.net
Thu Jul 21 08:48:36 PDT 2005

# from David Wheeler
# on Thursday 21 July 2005 08:16 am:

>> Conceptually, the most straightforward way to figure memory
>> consumption is to take the length() of each item
>Does this help?
>   http://search.cpan.org/dist/Devel-Size/Size.pm

Looks like a good source of info and verification, but maybe not 
something that you want to put in your production code:

  "Devel::Size, because of the way it works, can consume a considerable 
amount of memory as it runs. It will use five pointers, two integers, 
and two bytes worth of storage, plus potential alignment and bucket 
overhead, per thing it looks at."

I think Marvin's scheme is a good lightweight rough-estimate.  Remember 
that it was limiting the cache on number of items.  I think if you can 
provide a rough cap on memory usage and an estimate of how much error 
is typical, that is a huge improvement over the less-informed "number 
of items" cap.

Perl's "bursty" memory allocation should be part of that error.  If 
we're talking about 500MB +/- 5MB by the time all of the counting 
errors are collected that sounds good in exchange for the counting 
being done as quickly as possible.

If the collapse of the Berlin Wall had taught us anything, it was that
socialism alone was not a sustainable economic model.
--Robert Young

More information about the Pdx-pm-list mailing list