On Tue, Apr 20, 2004 at 11:16:07AM +0200, Tassilo von Parseval wrote:
> On Tue, Apr 20, 2004 at 09:18:12AM +0100 Nick Ing-Simmons wrote:

> > Would both give C "foo" calling sharepvn() on that would however look 
> > up that string and return a pointer to shared copy.
> > 
> > This is used by perl's hashes etc. so that you can just compare 
> > the PV values to get a fast proof of equality.
> > 
> > (You should unsharepvn() when you don't need it anymore - they are refcounted.)
> 
> Cool! So that's another treasure not to be found in perlapi.pod:
> 
>     #define Perl_sharepvn(sv, len, hash)
> 
> What about its third argument, though? It's an U32...so should 'hash' by
> used as a sort of ID to unambiguously identify pointers? I suppose I
> can't just set it to zero, can I?


It returns a pointer to the string in the shared string table (inserting
it if necessary). The shared string table is reference counted, so as Nick
says you must unshare anything when you finish with it. The hash is a value
calculated with PERL_HASH

Chasing the source code in hv.c, no it doesn't look like you can just use 0.

Nicholas Clark

Reply via email to