5 UV thing_size(SV *orig_thing) {
6 SV *thing = orig_thing;
7 UV total_size = sizeof(SV);
9 /* If they passed us a reference then dereference it. This is the
10 only way we can check the sizes of arrays and hashes */
11 if (SvOK(thing) && SvROK(thing)) {
15 switch (SvTYPE(thing)) {
19 /* Just a plain integer. This will be differently sized depending
20 on whether purify's been compiled in */
23 total_size += sizeof(sizeof(XPVIV));
25 total_size += sizeof(IV);
28 /* Is it a float? Like the int, it depends on purify */
31 total_size += sizeof(sizeof(XPVNV));
33 total_size += sizeof(NV);
36 /* Is it a reference? */
38 total_size += sizeof(XRV);
40 /* How about a plain string? In which case we need to add in how
41 much has been allocated */
43 total_size += sizeof(XPV);
44 total_size += SvLEN(thing);
46 /* A string with an integer part? */
48 total_size += sizeof(XPVIV);
49 total_size += SvLEN(thing);
51 /* A string with a float part? */
53 total_size += sizeof(XPVNV);
54 total_size += SvLEN(thing);
65 /* How much space is dedicated to the array? Not counting the
66 elements in the array, mind, just the array itself */
68 total_size += sizeof(XPVAV);
69 /* Is there anything in the array? */
70 if (AvMAX(thing) != -1) {
71 total_size += sizeof(SV *) * AvMAX(thing);
73 /* Add in the bits on the other side of the beginning */
74 total_size += (sizeof(SV *) * (AvARRAY(thing) - AvALLOC(thing)));
75 /* Is there something hanging off the arylen element? */
76 if (AvARYLEN(thing)) {
77 total_size += thing_size(AvARYLEN(thing));
96 croak("Unknown variable type");
102 MODULE = Devel::Size PACKAGE = Devel::Size
108 RETVAL = thing_size(orig_thing);