stefan k has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I'm currently working on glueing C and perl together (maybe there will be no more fopen() and fscanf() *grin*)
I'm currently working on glueing C and perl together (maybe there will be no more fopen() and fscanf() *grin*)
The problem is that a) the bindings are hard to understand and b) my code
leaks memory as hell. But I took almost everything more or less directly
from man perlembed and man perlguts, thus it can't be _that_
wrong...
BTW: this is a cooked down version for you, fellow Monks, that doesn't leak as much as
the original which has some SVs and stuff, but still ... it leaks :(
I post the code right below, but a quick word of warning: yes, it's C ;-)
/* compile with */ /* gcc -o monk monk.c `perl -MExtUtils::Embed -e ccopts -e ldopts` */ /* I tried this under Perl 5.6.0 and perl 5.005_3 */ # include <stdio.h> # include <EXTERN.h> # include <perl.h> # include <unistd.h> void call_perl(); int main(int argc, char **argv, char **env) { /* That's OK: */ printf("Testing perl embedding\n"); call_perl(); /* But in a loop we leak as hell */ while (1) { call_perl(); sleep(1); } } void call_perl(void) { static PerlInterpreter *my_perl; char *embedding[] = { "", "-e", "0" }; my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); eval_pv("print \"Perl Version: $]\\n\"",TRUE); perl_destruct(my_perl); perl_free(my_perl); }
Regards | Stefan K |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: MemLeak in Perl from C Calls
by kal (Hermit) on Apr 24, 2001 at 14:39 UTC | |
by stefan k (Curate) on Apr 24, 2001 at 15:00 UTC | |
by kal (Hermit) on Apr 24, 2001 at 15:37 UTC | |
by stefan k (Curate) on Apr 24, 2001 at 16:13 UTC | |
by SilverB1rd (Scribe) on Apr 24, 2001 at 17:58 UTC | |
| |
Re: MemLeak in Perl from C Calls
by Anonymous Monk on Apr 24, 2001 at 18:41 UTC | |
by tomw1975 (Sexton) on Jul 28, 2003 at 18:12 UTC | |
by mkprasad (Initiate) on Sep 06, 2009 at 21:18 UTC | |
by pierremallard (Initiate) on Feb 12, 2010 at 16:08 UTC | |
Re: MemLeak in Perl from C Calls
by ton (Friar) on Apr 24, 2001 at 21:27 UTC | |
by stefan k (Curate) on Apr 24, 2001 at 21:33 UTC |
Back to
Seekers of Perl Wisdom