I need to increase the reference count and this is the part I don't know how to do in XS

As BrowserUK indicated, you can use SvREFCNT_inc/SvREFCNT_dec (see perldoc perlapi) to increment/decrement the reference count in XS, or you can write perl wrappers for those XS functions if you want to do the manipulating from perl space:
use strict; use warnings; use Devel::Peek; use Inline C => Config => CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1; use Inline C => <<'EOC'; void incref(SV * sv) { SvREFCNT_inc(sv); } void decref (SV * sv) { SvREFCNT_dec(sv); } EOC my $str = 'hello world'; Dump $str; print "\n"; incref $str; Dump $str; print "\n"; decref $str; Dump $str;
The REFCNT of those 3 dumps is 1, 2, and 1 respectively.

I think I am better off refactoring parts of the XS code to perl and have the perl interpreter manage the reference counting

That wouldn't be my first choice, but it's certainly an option - especially if it's proving difficult to handle the reference counting correctly.

Cheers,
Rob

In reply to Re^3: PerlXS typemap and reference counting by syphilis
in thread PerlXS typemap and reference counting by joyrex2001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.