Commit | Line | Data |
e98cedbf |
1 | package Devel::Size; |
2 | |
e98cedbf |
3 | use strict; |
a6ea0805 |
4 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD %EXPORT_TAGS); |
e98cedbf |
5 | |
6 | require Exporter; |
7 | require 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 | ); |
fea63ffa |
27 | $VERSION = '0.54'; |
e98cedbf |
28 | |
29 | bootstrap Devel::Size $VERSION; |
30 | |
31 | # Preloaded methods go here. |
32 | |
33 | 1; |
34 | __END__ |
e98cedbf |
35 | |
36 | =head1 NAME |
37 | |
0bff12d8 |
38 | Devel::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 |
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 |
60 | when calling. |
61 | |
62 | =head1 FUNCTIONS |
63 | |
64 | =head2 size($ref) |
e98cedbf |
65 | |
5c2e1b12 |
66 | The C<size> function returns the amount of memory the variable |
0bff12d8 |
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. |
69 | |
70 | =head2 total_size($ref) |
5c2e1b12 |
71 | |
0bff12d8 |
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. |
5c2e1b12 |
78 | |
e98cedbf |
79 | =head2 EXPORT |
80 | |
0bff12d8 |
81 | None but default, but optionally C<size> and C<total_size>. |
e98cedbf |
82 | |
83 | =head1 BUGS |
84 | |
fea63ffa |
85 | Doesn't currently walk all the bits for code refs, formats, and |
6a9ad7ec |
86 | IO. Those throw a warning, but a minimum size for them is returned. |
e98cedbf |
87 | |
e98cedbf |
88 | =head1 AUTHOR |
89 | |
90 | Dan Sugalski dan@sidhe.org |
91 | |
92 | =head1 SEE ALSO |
93 | |
94 | perl(1). |
95 | |
96 | =cut |