The same problem with New() and Safefree():
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "stdlib.h" struct s { int field1; int field2; int field3; }; void do_simulation() { int i; struct s* m; New(1, (struct s*)m, 10000000, struct s); // do some computation with data // but for simplifying things I'll do a simple initialization for ( i=0; i<10000000; i++ ) { m[i].field1 = 0; m[i].field2 = 1; m[i].field3 = 2; } Safefree(m); } MODULE = MyModule PACKAGE = MyModule void sim() CODE: do_simulation();
Tested in a mod_perl environment and the memory continues to add up for each request (the final destination of this module will be the mod_perl environment)
In reply to Re: Calling a C function using malloc() in a XS
by Anonymous Monk
in thread Calling a C function using malloc() in a XS
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |