Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Using SV as key in hash

by grinder (Bishop)
on Jul 17, 2006 at 08:11 UTC ( #561701=note: print w/ replies, xml ) Need Help??

in reply to Using SV as key in hash

I don't think you need to play with HeSVKEY_set directly. Assuming key is an SV, why not use hv_store_ent instead?

CODE: SvREFCNT_inc(key); SvREFCNT_inc(val); hv_store_ent( hv, key, val, 0 );

• another intruder with the mooring in the heart of the Perl

Comment on Re: Using SV as key in hash
Download Code
Replies are listed 'Best First'.
Re^2: Using SV as key in hash
by liz (Monsignor) on Jul 17, 2006 at 08:52 UTC
    Hmmm... Are you implying that by default key values are already shared? As this code in sv.c seems to imply:
    HV * Perl_newHV(pTHX) { register HV *hv; register XPVHV* xhv; hv = (HV*)NEWSV(502,0); sv_upgrade((SV *)hv, SVt_PVHV); xhv = (XPVHV*)SvANY(hv); SvPOK_off(hv); SvNOK_off(hv); #ifndef NODEFAULT_SHAREKEYS HvSHAREKEYS_on(hv); /* key-sharing on by default */ #endif

    But I assume then that what is being shared, are char * rather than SV's? And sharing between different hashes doesn't really solve my optimization "problem", as I only want to use one hash. It's just that in many cases the value is the same as the key, and that it would therefore make sense to have them share the same SV.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://561701]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-11-26 00:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls