develooper Front page | perl.perl5.porters | Postings from October 2016

Re: hv.h hek definition

Thread Previous | Thread Next
Todd Rinaldo
October 25, 2016 15:54
Re: hv.h hek definition
Message ID:

> On Oct 24, 2016, at 10:45 AM, demerphq <> wrote:
>> ...
>> However, this may well be different on RISC systems which have strict
>> alignment constraints (ARM??).
>> Note that in the COW implementation, FC put the COW refcount at the end of
>> the string for similar alignment reasons.
>> I've had a vague idea at the back of my mind for a while that it might be
>> worth pre-allocating PVX buffers with N leading bytes (and SvOOK set),
>> where those N bytes are used to store the COW ref count. They could also
>> then be used as part of the HEK structure too. The size of N would depend
>> on the platform and alignment constraints, but might be 4 or 8. This
>> would add an extra memory overhead for strings, but in practice malloc()
>> libraries over allocate anyway (for example on my Linux system,
>> malloc/realloc returns (IIRC) 24+16n sized blocks, so strings with length
>> 0..16 would be unaffected, strings of length 17..24 would use an extra 16
>> bytes, lengths 25..32 unaffected. and so on).
>> But this is just a vague bit of handwaving.
> Well I have pushed the patch. I dont think it should matter, and if we
> find it does then we can tweak it further, or revert if necessary.
> Yves

Merged? great! 

So I was given the idea of doing this instead of doing char hek_flags, you could instead do this and not have to grow the struct. I suspect this would also fix the byte alignment concern?

PERL_BITFIELD32 hek_len    : 30;
PERL_BITFIELD32 hek_flags : 2;

You would then need to use an SV for your HEK if your hek_len was > 2^30. It is my belief that it should be an extremely rare event and punishable if abused :)

What I can't divine is what needs changing in hv_common to make it work though from what I can tell it should be related to:

Newx(k, HEK_BASESIZE + sizeof(const SV *), char);



Would this solve the byte alignment issue? Any hints on what would need changing in hv.c?


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About