Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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
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.

    Liz

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-21 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls