@EXPORT = qw(
);
-$VERSION = '0.51';
+$VERSION = '0.52';
bootstrap Devel::Size $VERSION;
$size = size("abcde");
$other_size = size(\@foo);
+ $foo = {a => [1, 2, 3],
+ b => {a => [1, 3, 4]}
+ };
+ $total_size = total_size($foo);
+
=head1 DESCRIPTION
This module figures out the real sizes of perl variables. Call it with
you're asking for the size of a reference, as it'll follow the
reference if you don't reference it first)
+The C<size> function returns the amount of memory the variable
+uses. If the variable is a hash or array, it only reports the amount
+used by the variable structure, I<not> the contents.
+
+The C<total_size> function will walk the variable and look at the
+sizes of the contents. If the variable contains references those
+references will be walked, so if you have a multidimensional data
+structure you'll get the total structure size. (There isn't, at the
+moment, a way to get the size of an array or hash and its elements
+without a full walk)
+
=head2 EXPORT
None by default.
Doesn't currently walk all the bits for code refs, globs, formats, and
IO. Those throw a warning, but a minimum size for them is returned.
-Also, this module currently only returns the size used by the variable
-itself, I<not> the contents of arrays or hashes, nor does it follow
-references past one level. That's for later.
-
=head1 AUTHOR
Dan Sugalski dan@sidhe.org
break;
case SVt_PVCV:
total_size += sizeof(XPVCV);
+ total_size += magic_size(thing, tracking_hash);
carp("CV isn't complete");
break;
case SVt_PVGV:
+ total_size += magic_size(thing, tracking_hash);
total_size += sizeof(XPVGV);
+ total_size += GvNAMELEN(thing);
+ /* Is there something hanging off the glob? */
+ if (GvGP(thing)) {
+ if (check_new(tracking_hash, GvGP(thing))) {
+ total_size += sizeof(GP);
+ }
+ }
carp("GC isn't complete");
break;
case SVt_PVFM:
case SVt_PVHV:
/* Is there anything in here? */
if (hv_iterinit((HV *)thing)) {
- SV *temp_thing;
- while (&PL_sv_undef !=
- (temp_thing = hv_iternextsv((HV *)thing, NULL, NULL))) {
- av_push(pending_array, temp_thing);
+ HE *temp_he;
+ while (temp_he = hv_iternext((HV *)thing)) {
+ av_push(pending_array, hv_iterval((HV *)thing, temp_he));
}
}
break;
+ case SVt_PVGV:
default:
break;
}