Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Perl with Swig C module not releasing memory

by Khen1950fx (Canon)
on May 10, 2013 at 20:08 UTC ( #1033019=note: print w/ replies, xml ) Need Help??


in reply to [Solved] Perl with Swig C module not releasing memory

I experimented with with lib.i. This is untested, but it's what I have so far:

/* lib.i */ % module libspace %{ #include "lib.h" extern x_space * new_space(); extern void destroy_space( x_space * space ); #ifdef PERL_OBJECT #define MAGIC_CLASS _wrap_libspace_var:: class _wrap_libspace_var : public CPerlObj { public: #else #define MAGIC_CLASS #endif SWIGCLASS_STATIC int swig_magic_readonly( pTHX_ SV * SWIGUNUSEDPARM(sv), MAGIC * SWIGUNUSEDPARM(mg) ) { MAGIC_PPERL croak("Value is read-only."); return 0; } #ifdef PERL_OBJECT }; #endif #ifdef __cplusplus extern "C" { #endif XS(_wrap_new_space) { { x_space * result = 0; int argvi = 0; dXSARGS; if ( ( items < 0 ) || ( items > 0 ) ) { SWIG_croak("Usage: new_space();"); } result = ( x_space * ) new_space(); ST(argvi) = SWIG_NewPointerObj( SWIG_as_voidptr(result), SWIGTYPE_p_x_space, 0 | 0 ); argvi++; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_destroy_space) { { x_space * arg1 = ( x_space * ) 0; void * argp1 = 0; int res1 = 0; int argvi = 0; dXSARGS; if ( ( items < 1 ) || ( items > 1 ) ) { SWIG_croak("Usage: destroy_space(space);"); } res1 = SWIG_ConvertPtr( ST(0), &argp1, SWIGTYPE_p_x_sp +ace, 0 | 0 ); if ( !SWIG_IsOK(res1) ) { SWIG_exception_fail( SWIG_ArgError(res1), "in method '" "destroy_space" "', argument " " +1" " of type '" "x_space *""'" ); } arg1 = ( x_space * ) (argp1); destroy_space(arg1); XSRETURN(argvi); fail: SWIG_croak_null(); } } %}
Does that help?


Comment on Re: Perl with Swig C module not releasing memory
Download Code
Replies are listed 'Best First'.
Re^2: Perl with Swig C module not releasing memory
by megaframe (Novice) on May 10, 2013 at 20:47 UTC

    I'm not entirely sure, I'm new to swig. What's all the extra definitions for?

    I can blind try them but I'd like to understand them so I know how I'm implementing things, since this is all part of much larger code.

      public service announcement,

      please don't try to analyze this statement by Khen1950fx, Khen1950fx, he just copy/pasted stuff, he doesn't know what it does, what its supposed to do, he's never used anything like it before, has no understanding of it

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (21)
As of 2015-07-31 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls