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

the '\0' at the end of the PV (was Re: COW in CORE and SvFAKE in older Perl)

Thread Previous | Thread Next
Nicholas Clark
May 1, 2003 04:14
the '\0' at the end of the PV (was Re: COW in CORE and SvFAKE in older Perl)
Message ID:
On Thu, May 01, 2003 at 12:02:15PM +0100, Tim Bunce wrote:
> > > 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.

I know that every scalar in perl is supposed to end with a "\0" byte one
beyond. I seem to remember that Enache Adrian was having problems with
mmap efficiency because the regexp engine assumes that it can read one
byte beyond the end of a string (although IIRC it then correctly doesn't
use it)

However, does anything inside perl actually expect this byte to be "\0"?
Or is it only needed on an SV if you use that SV as a filename or other
such string passed out to the OS?

This shards idea seems to be similar to Jarkko's VVs proposal:

There was some discussion then about how it could be implemented, but no-one
had a pressing problem to solve that motivated a drive to implementation.
You (Aaron) may now have presented a problem.

Nicholas Clark

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