[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: New way to do XS constants



On Fri, Jan 07, 2000 at 10:08:12AM +0000, Graham Barr wrote:
> On Fri, Jan 07, 2000 at 09:58:56AM +0000, Tim Bunce wrote:
> > FYI: All those advantages also apply to this very simple method:
> > 
> >   I32
> >   constant()
> >         PROTOTYPE:
> >     ALIAS:
> >         CONST_NAME_1 = 1
> >         CONST_NAME_2 = 2
> >         CONST_NAME_3 = 3
> >         CONST_NAME_4 = 4
> >     CODE:
> >     RETVAL = ix;
> >     OUTPUT:
> >     RETVAL
> > 
> > (The 1, 2, 3, 4 can be #defined values.)
> > 
> > Using a single XS sub and multiple XS aliases instead of multiple perl
> > subs uses very little memory (far less than multiple perl subs).
> > It also has a very low start-up overhead (just one newXS() call each).
> 
> But this does not create a constant sub. It also does not allow you use
> #ifdef for the constants.

Ah yes, I'd forgotten that approach wasn't enough. That's what I get
for being away from the perl source too long ;-)

> Take a look at the end of IO.xs

        newCONSTSUB(stash,"POLLPRI", newSViv(POLLPRI));

I hadn't used newCONSTSUB for DBD::Oracle (where I use the xsubpp ALIAS)
because I wanted more backwards portability. But I could always #ifdef
a local copy of it for older perls.

Thanks.

Tim.


Follow-Ups from:
Graham Barr <gbarr@pobox.com>
Graham Barr <gbarr@pobox.com>
References to:
Tye McQueen <tye@metronet.com>
Tim Bunce <Tim.Bunce@ig.co.uk>
Graham Barr <gbarr@pobox.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]