Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: XS: returning a 64-bit unsigned int?

by BrowserUk (Pope)
on Sep 27, 2011 at 08:06 UTC ( #928044=note: print w/ replies, xml ) Need Help??


in reply to Re^3: XS: returning a 64-bit unsigned int?
in thread XS: returning a 64-bit unsigned int?

There is a SvIsUV_on(sv)

Not in the docs I'm looking at. Where did you dig that one up from?

and you didn't handle magic. If it's just an internal scalar, you could get away with not doing those,

No, I never handle magic. It's not laziness but a design choice. The reason I drop into XS/I::C is for performance. There is no point in doing that if you then allow people to pass you arrays that are tied to disk, or scalars that use post-its as backing store :)

IMO the way perl handles magic in-line, is all wrong anyway. It imposes huge costs for something that is actually quite a rare event. It ought to be possible to make a single determination at the top of a routine and defer to a separate routine that handles magic when needed, thus leaving the main-line code free of such considerations. But that's another wish list item that it's far too late to consider at this point.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^4: XS: returning a 64-bit unsigned int?
Re^5: XS: returning a 64-bit unsigned int?
by ikegami (Pope) on Sep 27, 2011 at 08:57 UTC

    It ought to be possible to make a single determination at the top of a routine

    That is how it's done. A single SvGETMAGIC if you read a scalar, no matter how many times you read it. A single SvSETMAGIC if you write to a scalar, no matter how many times you write to it. You don't want to call magic twice, and not just for performance reasons.

      That is how it's done. A single SvGETMAGIC if you read a scalar, no matter how many times you read it. A single SvSETMAGIC if you write to a scalar, no matter how many times you write to it.

      And if you're processing a real array containing a million real scalars, then that's 2 million redundant, time consuming function calls conditional tests.

      Addition: Were it possible to perform a single test on the array to detect magic, it might be worth doing to allow me to gracefully reject it. But as is, the only sensible option is to document that only real arrays of real scalars are acceptable input and fail noisily if I am given anything else.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        If they're redundant, don't do them. Generally speaking, though, they're not redundant. The outcome of each test is independent of the others. Magic can be tied to an element without being tied to the array, and the use of GET and SET magic is independent.

        $ perl -MDevel::Peek -E' sub TIESCALAR { bless \my $x; } sub FETCH { 3 } my @a = (6,7); tie $a[1], __PACKAGE__; say $a[0]; say $a[1]; Dump(\@a); ' 6 3 SV = IV(0x9a22324) at 0x9a22328 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x9a3c2e8 SV = PVAV(0x9a23174) at 0x9a3c2e8 REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x9a3af28 FILL = 1 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x9a21764) at 0x9a21768 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 6 Elt No. 1 SV = PVMG(0x9a64d50) at 0x9a21898 REFCNT = 1 FLAGS = (GMG,SMG,RMG,pIOK,pPOK) IV = 3 NV = 0 PV = 0x9a370d0 "3"\0 CUR = 1 LEN = 12 MAGIC = 0x9a46460 MG_VIRTUAL = &PL_vtbl_packelem MG_TYPE = PERL_MAGIC_tiedscalar(q) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x9a22258 SV = IV(0x9a22254) at 0x9a22258 REFCNT = 1 FLAGS = (ROK) RV = 0x9a4f4a0

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-09-20 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls