import Devel-Size 0.53 from CPAN
[p5sagit/Devel-Size.git] / Size.pm
CommitLineData
e98cedbf 1package Devel::Size;
2
e98cedbf 3use strict;
a6ea0805 4use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD %EXPORT_TAGS);
e98cedbf 5
6require Exporter;
7require DynaLoader;
8
a6ea0805 9@ISA = qw(Exporter DynaLoader);
e98cedbf 10
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.
14
15# This allows declaration use Devel::Size ':all';
16# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17# will save memory.
a6ea0805 18%EXPORT_TAGS = ( 'all' => [ qw(
0bff12d8 19 size total_size
e98cedbf 20) ] );
21
a6ea0805 22@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
e98cedbf 23
a6ea0805 24@EXPORT = qw(
e98cedbf 25
26);
0bff12d8 27$VERSION = '0.53';
e98cedbf 28
29bootstrap Devel::Size $VERSION;
30
31# Preloaded methods go here.
32
331;
34__END__
e98cedbf 35
36=head1 NAME
37
0bff12d8 38Devel::Size - Perl extension for finding the memory usage of Perl variables
e98cedbf 39
40=head1 SYNOPSIS
41
0bff12d8 42 use Devel::Size qw(size total_size);
e98cedbf 43
0bff12d8 44 my $size = size("A string");
45
46 my @foo = (1, 2, 3, 4, 5);
47 my $other_size = size(\@foo);
48
49 my $foo = {a => [1, 2, 3],
5c2e1b12 50 b => {a => [1, 3, 4]}
51 };
0bff12d8 52 my $total_size = total_size($foo);
5c2e1b12 53
e98cedbf 54=head1 DESCRIPTION
55
0bff12d8 56This module figures out the real sizes of Perl variables in bytes.
57Call functions with a reference to the variable you want the size
58of. If the variable is a plain scalar it returns the size of
59the scalar. If the variable is a hash or an array, use a reference
60when calling.
61
62=head1 FUNCTIONS
63
64=head2 size($ref)
e98cedbf 65
5c2e1b12 66The C<size> function returns the amount of memory the variable
0bff12d8 67returns. If the variable is a hash or an array, it only reports
68the amount used by the structure, I<not> the contents.
69
70=head2 total_size($ref)
5c2e1b12 71
0bff12d8 72The C<total_size> function will traverse the variable and look
73at the sizes of contents. Any references contained in the variable
74will also be followed, so this function can be used to get the
75total size of a multidimensional data structure. At the moment
76there is no way to get the size of an array or a hash and its
77elements without using this function.
5c2e1b12 78
e98cedbf 79=head2 EXPORT
80
0bff12d8 81None but default, but optionally C<size> and C<total_size>.
e98cedbf 82
83=head1 BUGS
84
6a9ad7ec 85Doesn't currently walk all the bits for code refs, globs, formats, and
86IO. Those throw a warning, but a minimum size for them is returned.
e98cedbf 87
e98cedbf 88=head1 AUTHOR
89
90Dan Sugalski dan@sidhe.org
91
92=head1 SEE ALSO
93
94perl(1).
95
96=cut