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

Re: hv.h hek definition

Thread Previous | Thread Next
From:
Todd Rinaldo
Date:
October 25, 2016 15:54
Subject:
Re: hv.h hek definition
Message ID:
26AAA6AB-52B2-4A85-881A-1FA52C8D4285@cpanel.net

> On Oct 24, 2016, at 10:45 AM, demerphq <demerphq@gmail.com> 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);

and

HEf_SVKEY

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

Thanks,
Todd


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About