http://qs1969.pair.com?node_id=1085060


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

Are you suggesting to make perl code explicitly call the wrapper (instead of relying on DESTROY) and keeping a separate (non perl) refcount for every person pointer in the module?

Call the wrapper from DESTROY.

The library you are using knows about the references and counts, so you should be able to figure out in your XS code whether to really free an object (person, in this case). In Perl code (DESTROY), simply call your XS function, which will know what to do.

Replies are listed 'Best First'.
Re^4: Managing C library memory in XS
by petermogensen (Sexton) on May 05, 2014 at 12:58 UTC
    The library you are using knows about the references and counts

    Ahh.. No. It does not.

    There's not more to the C library interface than I described. Functions returning pointers and a documentation which tells you if you are allowed to free the returned pointer. No reference counting. It's plain C without any magic.

      As long as there is a way to know this programmatically, you are good: program it into your XS module. If there is not, I think you're screwed no matter at which level you code it.
        I think you could say that about any programming problem.