Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello, all

I have a problem with memory reallocation when using a Perl interpreter embeded in my application. (I use few interpreters in few threads. For each interpreter exists its own thread.)

It seems that if we create more than one interpreter we must delete them all at one place.

Flat example:
0: 1: int main(int argc, char **argv) 2: { 3: PerlInterpreter *one_perl, *two_perl; 4: char *one_args[] = { "one_perl", "-e", "print qq(Hi, I'm $^X\n +)" }; 5: char *two_args[] = { "two_perl", "-e", "print qq(Hi, I'm $^X\n +)" }; 6: 7: PERL_SYS_INIT3(&argc,&argv,&env); 8: one_perl = perl_alloc(); 9: 10: PERL_SET_CONTEXT(one_perl); 11: perl_construct(one_perl); 12: 13: PERL_SET_CONTEXT(one_perl); 14: perl_parse(one_perl, NULL, 3, one_args, (char **)NULL); 15: 16: PERL_SET_CONTEXT(one_perl); 17: perl_run(one_perl); 18: 19: PERL_SET_CONTEXT(one_perl); 20: perl_destruct(one_perl); 21: 22: PERL_SET_CONTEXT(one_perl); 23: perl_free(one_perl); 24: 25: two_perl = perl_alloc(); 26: PERL_SET_CONTEXT(two_perl); 27: perl_construct(two_perl); 28: PERL_SET_CONTEXT(two_perl); 29: perl_parse(two_perl, NULL, 3, two_args, (char **)NULL); 30: PERL_SET_CONTEXT(two_perl); 31: perl_run(two_perl); 32: //PERL_SET_CONTEXT(one_perl); 33: //perl_free(one_perl); 34: PERL_SET_CONTEXT(two_perl); 35: perl_destruct(two_perl); 36: PERL_SET_CONTEXT(two_perl); 37: perl_free(two_perl); 38: 39: PERL_SYS_TERM(); 40: 41: return 0; 42:}

Exception is thrown in 29 line. If we comment 22, 23 line and uncomment 32 and 33 lines, then all will be OK.

Questions: Please, point me to error in the code or propose method to delete interpreters separately.


In reply to perl_free problem by iladyko_vision

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found