Hi,

I'm not sure if this is the right list to ask this question, but I'll give
it a go and if I'm wrong you can tell me so (and maybe some hint to where I
should turn instead).

I'm using perl v5.6.0 i i386-openbsd. I've read man perl[embed|guts|api].

I'm writing a program where I need to use perl from within a C++/C program.
As part of layering interfaces in the program structure I wrote a simple C++
class to handle the instantation of the perl interpreter and also conversion
between C style variables to perl dito.

My problem is this. No matter how I try I get a significant memory increase
for each iteration I run through.

In the section "Maintaining multiple interpreter instances" in man perlembed
there is a short program outline. Even if I copy it (and add some necessery
things like a main function), the program increases it's memory usage.

The sketch is as follows:

<code>
PL_perl_destruct_level = 1;

while(1)
{
    ... // 1
    perl_construct(my_perl);
    ... // 2
    perl_destruct(my_perl);
    perl_free(my_perl);
    ... // 3
}
</code>

I've added a:

<code>
    PerlInterpreter *my_perl = perl_alloc();
</code>

 at // 1 and a:

<code>
    char *args[] = { NULL, "test.pl", NULL };
    perl_parse(my_perl, NULL, 2, args, (char**)NULL);
    perl_run(my_perl);
</code>

at // 2.

test.pl only contains:

<code>
#!/usr/local/bin/perl
print "Hello world!\n";
1;
</code>

In the end I'd like to add a call_pv() as well (in reality this is what I
would like to call multiple times [and it works if thats the only thing in
the while(1) loop]).

I don't have that much experience with embedding perl but I'm ok with both
C/C++ and perl by themselves. I've tried to move things out of the while(1)
loop. The only way I can get no memory usage increase is to remove
everything execpt the perl_run() call. Since my perl files won't change that
often I could of course make a list of what files have been sent to
perl_parse() and only re-read them if they change. But it seemes very
backward that perl doesn't release all memory if I use perl_destruct() and
perl_free(). So I guess I'm making a mistake somewhere. I just dont' see it.

I use the output from "perl -MExtUtils::Embed -e ccopts" and
"perl -MExtUtils::Embed -e ldopts" and "perl -MExtUtils::embed -e
xsinit -- -o perlxsi.c" and gcc to compile the application.

--
Aigars Grins




Reply via email to