develooper Front page | perl.perl6.internals | Postings from February 2001

Re: PDD 2, vtables

Thread Previous | Thread Next
Dan Sugalski
February 17, 2001 11:34
Re: PDD 2, vtables
Message ID:
At 04:55 PM 2/17/2001 +0000, Simon Cozens wrote:
>On Mon, Feb 05, 2001 at 05:14:44PM -0500, Dan Sugalski wrote:
> > =item new
> >
> >    void               new(PMC[, key]);
> >
> > Creates a new variable of the appropriate type out of the passed PMC,
> > destroying the current contents if there are any. This is a class
> > function.
>Can I suggest this becomes
>     PMC                 new(PMC[, key]);
>It gets really hard to get things started otherwise:

Well, the idea was that the passed in PMC is either reusable, can be 
trashed, or is an aggregate of some point and we may autoviv the element 
corresponding to the key.

Dunno if that was as well thought out as it ought to be, but it's not 
unreasonable to expect that the passed in PMC is trashable and has been 
previously cleaned up if it needed it.

>     PMC mypmc;
>     (;
>     printf("mypmc's class is %s\n", (mypmc->vtbl->name)(mypmc));
>If PMC is a pointer to a structure, "new" will need to allocate memory for a
>new structure, and hence the value of mypmc will have to change.

Nope. PMC structures will be parcelled out from arenas and not malloc'd, 
and they won't be freed and re-malloced much. If we're passing in a PMC 
pointer, we won't be reallocating the memory pointed to--rather we'll be 
reusing it.

>The structure
>     struct _pmc {
>         VTABLE* vtbl;
>         void* private_data;
>     };
>makes it nice and easy to morph one PMC class into another;

We talked a few months ago about the structure of the base PMC piece. IIRC 
the general consensus is we need a flags field, a field for the garbage 
collector, and were going to tack on an integer and float fields as well 
for speed.


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

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