From: Dan Sugalski Date: Tue, 8 Oct 2002 17:53:32 +0000 (-0800) Subject: import Devel-Size 0.02 from CPAN X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6ea0805056e5f7af2919c2a4eb13586fca77269;p=p5sagit%2FDevel-Size.git import Devel-Size 0.02 from CPAN git-cpan-module: Devel-Size git-cpan-version: 0.02 git-cpan-authorid: DSUGAL git-cpan-file: authors/id/D/DS/DSUGAL/Devel-Size-0.02.tar.gz --- diff --git a/Size.pm b/Size.pm index 7cc20db..a85067e 100644 --- a/Size.pm +++ b/Size.pm @@ -1,13 +1,12 @@ 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. @@ -16,16 +15,16 @@ our @ISA = qw(Exporter DynaLoader); # 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; @@ -62,7 +61,7 @@ None by default. 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 the contents of arrays or hashes, nor does it follow +itself, I the contents of arrays or hashes, nor does it follow references past one level. That's for later. =head1 AUTHOR diff --git a/Size.xs b/Size.xs index d0e1f1e..89f0912 100644 --- a/Size.xs +++ b/Size.xs @@ -2,6 +2,10 @@ #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); @@ -78,7 +82,27 @@ UV thing_size(SV *orig_thing) { } 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"); @@ -101,8 +125,9 @@ UV thing_size(SV *orig_thing) { MODULE = Devel::Size PACKAGE = Devel::Size -UV -size(SV *orig_thing) +IV +size(orig_thing) + SV *orig_thing CODE: { RETVAL = thing_size(orig_thing);