Problems? Is your data what you think it is? | |
PerlMonks |
Re: Re: Perl Internals: Hashesby hv (Prior) |
on Apr 14, 2004 at 22:11 UTC ( [id://345222]=note: print w/replies, xml ) | Need Help?? |
... hv = (HV*)NEWSV(502,0); ... ... creates a new hash. We can see that the basic memory needed is 502 bytes That's not correct: the first parameter to NEWSV is an identifier, used only for malloc debugging. It is the second parameter that provides the size, and a value of zero means "give me a new empty SV - I'll fill it in myself". It is the following call to sv_upgrade((SV *)hv, SVt_PVHV) that actually turns this into something capable of storing a hash. In particular it allocates the struct xpvhv, defined in hv.h:
Also the number of buckets does increase in powers of 2, as shown by the example code in demerphq's response. S_more_he() is not relevant to this - it is (I think) fetching a new structure from a malloc arena. The routine you want is S_hsplit() which quite early on does a nice clear:
Hugo
In Section
Seekers of Perl Wisdom
|
|