in reply to Re^2: C++ object & PERL garbage collection
in thread C++ object & PERL garbage collection
I wonder what would happen if the reference count were incremented before returning:my $dsgn = create_new(); $dsgn->(method); sub create_new { my $ret = new (c++_object); return $ret; }
I don't think there exists a perl function/module that implements a reference count increment - in which case you'd need to do it with Inline::C/XS/SWIG. (I guess SWIG can help out there ... I know nothing about it.) Even if incrementing the reference count does work, that doesn't guarantee that it's the most appropriate thing to do.my $dsgn = create_new(); $dsgn->(method); sub create_new { my $ret = new (c++_object); refcnt_inc($ret); return $ret; }
use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void refcnt_inc(SV * sv) { SvREFCNT_inc(sv); } SV * get_refcnt(SV * sv) { return newSVuv(SvREFCNT(sv)); } EOC $x = 1; print get_refcnt($x), "\n"; refcnt_inc($x); print get_refcnt($x), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: C++ object & PERL garbage collection
by Anonymous Monk on Sep 23, 2006 at 02:28 UTC | |
|
Re^4: C++ object & PERL garbage collection
by diotalevi (Canon) on Sep 23, 2006 at 03:05 UTC |