(I'm not sure if I've missed all the fun here before I subscribed, but
I can't anything on the RFC list that mentions the following)

perl5 has a tangle of SvPV macros to allow C code to get a pointer
to the scalar. (or the "private", with or without the length, and
more relating to utf8 that don't even appear to be documented)

Has any thought yet been given to the API to get scalars?

Jarkko posted an idea on p5p of "Virtual Values" which would permit a
scalar to point to another scalar's buffer, rather than its own.
Currently the perl5 API assumes that you get a read-write pointer, and that
the thing it points to is "\0" terminated. This makes it hard to implement
copy on write, or to allow a pointer to a sub-length of the parent
scalar's buffer.

IIRC Ilya mailed p5p bemoaning the fact that perl's SVs use a continuous
buffer. A split-buffer representation (where a hole is allowed in the
middle of the buffer data) permits much faster replacement type operations,
as there is less copying, and you can move the hole around to suit your
needs.

So I was wondering if perl6 was going to replace SvPV* with something that
allows the caller to say whether they'd like

* read only or read write
* buffer all in one block or can cope with a hole (plus tell me where it is)
* null terminated buffer or don't care

and possibly

* data must be in utf8 or tell me what the data is in

although this might be better done as caller specifies 1 or more acceptable
encodings they could cope with, and SvPV* returns data in whatever
requires least work to translate consistent with maintaining accuracy.

In particular specifying read/write versus read only would allow
perl to treat scalars as copy-on-write which would mean things like
$a=$b wouldn't actually copy anything (wasting time and (shared) memory
pages) until either $a or $b got changed.
[I have this feeling that there's a bit of this already in sv.c, but I'm
not sure how much]

Nicholas Clark

Reply via email to