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)

>I can see some obvious disadvantages here - AV implementers have to
>include a whole bunch of boilerplate code for methods which are of
>no concern to them, and lots of parameters and return values have
>to be passed back and forth unnecessarily.

Which is one of the places that good inheritance can come in handy. I'm 
also thinking it's a place (vtable coding in general) where the PIL would 
be a big win. (Both in the table definitions and in the routines for the 
tables)

                                        Dan

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

Reply via email to