On Tue, Apr 20, 2004 at 09:18:12AM +0100 Nick Ing-Simmons wrote:

> Scott T. Hildreth <[EMAIL PROTECTED]> writes:

> >> > 
> >> >  .. so the address of $fldnm is always the same (static).  Therefore the
> >> > fld->names that are sent in all point to the same address.  How do I get
> >> > a new SV so that the memory area is different. 
> >> 
> >> By making a copy:
> >> 
> >>     fld->name = savepv( SvPV(name, len) );
> 
> There is another useful function - sharepvn()
> This returns a char * (which should be considered readonly) but 
> the _same_ char * will be returned for same string.
> 
> So   set_name($obj,'foo')
> and 
>      set_name($obj,f =>('o' x 2)); 
> 
> 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?

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval

Reply via email to