develooper Front page | perl.perl5.porters | Postings from May 2003

Re: COW in CORE and SvFAKE in older Perl

Thread Previous | Thread Next
Tim Bunce
May 1, 2003 04:02
Re: COW in CORE and SvFAKE in older Perl
Message ID:
> > I'm in the middle of writing a module that I thought would address some
> > SpamAssassin performance problems (or at least provide me with the
> > platform to address them) by creating SvFAKE values based on a substring
> > of original string (a "shard" as I've been referring to it) without
> > allocating new memory and/or copying.

> > $self->{msg_as_array} = [split /\r?\n/, $$msgref]; 

> > However, support for SvFAKE in 5.6.1 seems to be very limited (in fact,
> > it's really only working if you are SvFAKEing an SVt_PVGV, and even then
> > I'm not sure how general-purpose it is). This is unfortunate because it
> > seems to mean that I have to resort to MAGIC in order to prevent Perl
> > from trying to free my data (I've already marked it as SvREADONLY).

Perhaps SvFAKE is the wrong approach. I think just setting SvLEN to 0
would stop the PV memory being freed when the SV is freed.

No need for SvFAKE. Just set SvREADONLY on the 'shards' and the
message SV they point into. Then the only remaining problem is to
make sure that the message SV isn't freed before the shard SVs.

The sv_add_backref() mechanism could probably handle that for you.

Tim [who may be well off the mark as I've not been paying attention]

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About