4 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD %EXPORT_TAGS);
9 @ISA = qw(Exporter DynaLoader);
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
15 # This allows declaration use Devel::Size ':all';
16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 %EXPORT_TAGS = ( 'all' => [ qw(
22 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
29 bootstrap Devel::Size $VERSION;
31 # Preloaded methods go here.
38 Devel::Size - Perl extension for finding the memory usage of Perl variables
42 use Devel::Size qw(size total_size);
44 my $size = size("A string");
46 my @foo = (1, 2, 3, 4, 5);
47 my $other_size = size(\@foo);
49 my $foo = {a => [1, 2, 3],
52 my $total_size = total_size($foo);
56 This module figures out the real sizes of Perl variables in bytes.
57 Call functions with a reference to the variable you want the size
58 of. If the variable is a plain scalar it returns the size of
59 the scalar. If the variable is a hash or an array, use a reference
66 The C<size> function returns the amount of memory the variable
67 returns. If the variable is a hash or an array, it only reports
68 the amount used by the structure, I<not> the contents.
70 =head2 total_size($ref)
72 The C<total_size> function will traverse the variable and look
73 at the sizes of contents. Any references contained in the variable
74 will also be followed, so this function can be used to get the
75 total size of a multidimensional data structure. At the moment
76 there is no way to get the size of an array or a hash and its
77 elements without using this function.
81 None but default, but optionally C<size> and C<total_size>.
85 Doesn't currently walk all the bits for code refs, globs, formats, and
86 IO. Those throw a warning, but a minimum size for them is returned.
90 Dan Sugalski dan@sidhe.org