On Mon, 7 Aug 2000, Uri Guttman wrote:
>
> can someone write up a short description (or rfc is you prefer) on
> vtables. i gather that they are a per value (for some definition of
> value) dispatch table which handles the ways a value can be
> accessed. everyone is using that term and i haven't seen a concrete
> definition here.
It's basically a method of indirection. You have a table of
functions--whate each entry in the table does is fixed, but how it does it
depends on which table you use.
With the current perl 5 interface, if you want the integer value of a
scalar you call SvIV:
foo = SvIV(SV *some_pointer)
while with vtables it'd be (and excuse the syntax, I always get this
wrong doing it off the cuff):
foo = (some_pointer->vtable[GET_INT])(some_pointer);
For plain int scalars, that might translate to a call to:
int plain_int(PMC *some_pointer) {
return some_pointer->int_cache;
}
while for a string-only scalar it might be:
int conv_int(PMC *some_pointer) {
return make_int(some_pointer->pv_cache);
}
This way you can have tailored functions to do just what you need--no need
to check to see if you need to upgrade, and the common functions will
hopefully be small and in the cache pretty much constantly.
Dan