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

Re^3: Managing C library memory in XS

by sundialsvc4 (Abbot)
on May 05, 2014 at 18:14 UTC ( [id://1085102]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Managing C library memory in XS
in thread Managing C library memory in XS

Basically, “yes it is.”   And JSON::XS is a wonderful high-performance encoder/decoder for that reason.   But you really aren’t dealing with “multiple persistent internal library-states” and you really aren’t updating anything, either.   Furthermore, that package is intentionally all-about-speed.   The situation suggested to me in the OP appeared to be a little bit different; hence my suggestions for what I thought might work better in the OP’s specific case.   (And they are meant to be nothing more than that.)   There is noone way to do this sort of thing.”   The best way to “manage C-library memory in XS” really depends altogether upon the library in question.

Replies are listed 'Best First'.
Re^4: Managing C library memory in XS
by petermogensen (Sexton) on May 05, 2014 at 18:29 UTC

    Speed is not completely irrelevant for the task at hand. That's antoher reason why I'm reluctant to try copy everything back and forth and like the idea of just blessing a reference to a pointer. Also, the C library actaully does have methods for almost everything, so there's very little API use for actually having wrapper Per blessed-hash objects. to manage stuff.

    But let me ask the question another way:

    What does the Perl interpreter guarantee about dual value objects? Is there any official guarantee of semantics?

    I Mean... Scalar::Util even advertises the use of dualvar() to set both an interger and a string value on a scalar. So some guarantees must be provided.

    If the guarantee is to alway copy and preserve the entire struct SV and struct xpvmg... and in general support multi-valued vars (PV,IV,NV) ...and.. hmm.. NV being the same size as IV, then there should be nothing wrong with the approach.

      Not thinking so much of “blessed” anythings.   Instead, thinking of the exchange of (say, a “person”) consisting of a hash-type variable ... which might, say, include a “_personid” element provided by the library and which contains the moniker I spoke of.   Basically, you would be shifting data between C structures and hashes ... a lot ... if you pursued my suggestion.   Which, I will very freely admit, absolutely might not be the right thing for you to do in your case!   (I was wrong once ... lessee, how many years ago was it, now?   Or am I wrong about that ...?)   ;-)

      As far as I know, the dual-value feature is basically there in the name of efficiency, so that you can have '123' and 123 at the same time.   But I am not qualified to answer your question about interpreter guarantees or the lack thereof.

        As far as I know, the dual-value feature is basically there in the name of efficiency, so that you can have '123' and 123 at the same time. But I am not qualified to answer your question about interpreter guarantees or the lack thereof.

        Having dual values IV/PV is not so rare a use case. One example is error-codes. Many modules provide the error message in string context and the integer error code when using int().

        I also just found an example of PV/NV duality

        What my suggestion did was IV/NV duality. But with the little twist that the SVf_NOK flag was not set. It was for internal usage of back-referencing the owning object only. ... Who's using that NV slot anyway?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-03-19 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found