At 06:01 PM 12/7/00 +0000, Piers Cawley wrote:
>Dan Sugalski <[EMAIL PROTECTED]> writes:
> > At 01:20 PM 12/7/00 +0000, David Mitchell wrote:
> > >Dan Sugalski <[EMAIL PROTECTED]> wrote:
> > >
> > > >     print $foo[0];
> > > > is
> > > >    foo->get_string[UTF_8](ARRAY, 0);
> > > > while
> > > >    print $foo
> > > > is
> > > >    foo->get_string[UTF_8](SCALAR);
> > >
> > >Just to clarify:
> > >
> > >does the get_string method in an AV's vtable do an indexing lookup,
> > >grab the relevant SV pointer, then call that SV's get_string() method,
> > >and forward the return value? ie
> > >
> > >char * AV_get_string_utf8(AV *av, int index) {
> > >         SV* sv = av->whatever[index];
> > >         return sv->get_string[UTF_8](sv);
> > >}
> > >
> > >What advantage(s) does this buy?
> >
> > It means that array and hash elements don't have to be scalars, and
> > that the scalar fetch/store opcodes don't need to check array and
> > hash types.
> >
> >
> > One of the memory use wins that Chip talked about with Topaz was
> > having specialized array and hash types--string, integer, and float
> > arrays were the big ones. If you do this (and lots of folks do)
> >
> >
> >    my @foo;
> >    @foo = <SOME_HUGE_FILE>;
> >
> > then having @foo be a specialized array that only holds strings
> > (requiring a declaration, of course) is a memory win. Those array
> > elements don't have to be pointers to scalars--they can be pointers
> > to strings, tossing all the unneeded scalar bits. And while scalars
> > might be slightly slimmer in p6, there's still non-string bits that
> > we can toss, along with possibly a level of indirection in there.
> > (The array could hold all the string info and not even have to hold
> > pointers to each string's info)
>
>Excuse me if I'm stating the obvious here, but presumably as soon as
>you start doing something like $total += $array[$index_of_a_number]
>then $array[$index_of_a_number] will acquire an SV like decoration,

Nope. The get_* functions in the vtable will be required to return the type 
asked for, but they are *not* required to convert the scalar in any way. If 
@array was marked as a string array, accessing an element doesn't have to 
promote the entire array to scalars. It's perfectly OK for the array to 
stay strings.

>but doing
>
>$array[$some_index] = $not_a_string_and_has_no_stringify_overload
>
>could be made to throw an exception.

That's up to Larry. If you declared it:

  my str @array;

then it'd probably upgrade the array to an array of scalars (and take a 
rather large hit if the array's big). I'd like to also be able to do:

   my str @array : strict;

(or something--the attribute name is important in general, but not right 
now) and in that case have perl yell if you try and stick a non-string into 
the array, though for standard scalars and things emulating them (bigints, 
complex numbers, etc) I can see not yelling, and just taking the string 
conversion. (I would yell for objects, personally)

>Or would one need to explicitly copy something from the array into an
>SV type variable before getting SV magic.

Nope. It should be transparent, and having to copy's not transparent, so we 
shouldn't require it.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to