package Devel::Size;
-require 5.005_62;
use strict;
-use warnings;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD %EXPORT_TAGS);
require Exporter;
require DynaLoader;
-our @ISA = qw(Exporter DynaLoader);
+@ISA = qw(Exporter DynaLoader);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# This allows declaration use Devel::Size ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
-our %EXPORT_TAGS = ( 'all' => [ qw(
+%EXPORT_TAGS = ( 'all' => [ qw(
size
) ] );
-our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
+@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
-our @EXPORT = qw(
+@EXPORT = qw(
);
-our $VERSION = '0.01';
+$VERSION = '0.02';
bootstrap Devel::Size $VERSION;
Only does plain scalars and arrays. No sizes for hashes, globs, code refs, or magic scalars. Yet.
Also, this module currently only returns the size used by the variable
-itself, E<not> the contents of arrays or hashes, nor does it follow
+itself, I<not> the contents of arrays or hashes, nor does it follow
references past one level. That's for later.
=head1 AUTHOR
#include "perl.h"
#include "XSUB.h"
+#if !defined(NV)
+#define NV double
+#endif
+
UV thing_size(SV *orig_thing) {
SV *thing = orig_thing;
UV total_size = sizeof(SV);
}
break;
case SVt_PVHV:
- croak("Not yet");
+ /* First the base struct */
+ total_size += sizeof(XPVHV);
+ /* Now the array of buckets */
+ total_size += (sizeof(HE *) * (HvMAX(thing) + 1));
+ /* Now walk the bucket chain */
+ {
+ HE *cur_entry;
+ IV cur_bucket = 0;
+ puts("Foo!");
+ for (cur_bucket = 0; cur_bucket <= HvMAX(thing); cur_bucket++) {
+ cur_entry = *(HvARRAY(thing) + cur_bucket);
+ while (cur_entry) {
+ total_size += sizeof(HE);
+ if (cur_entry->hent_hek) {
+ total_size += sizeof(HEK);
+ total_size += cur_entry->hent_hek->hek_len - 1;
+ }
+ cur_entry = cur_entry->hent_next;
+ }
+ }
+ }
break;
case SVt_PVCV:
croak("Not yet");
MODULE = Devel::Size PACKAGE = Devel::Size
-UV
-size(SV *orig_thing)
+IV
+size(orig_thing)
+ SV *orig_thing
CODE:
{
RETVAL = thing_size(orig_thing);