in reply to Calling a C function using malloc() in a XS
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calling a C function using malloc() in a XS
by syphilis (Archbishop) on Aug 08, 2010 at 13:12 UTC | |
by Anonymous Monk on Aug 08, 2010 at 15:26 UTC | |
by syphilis (Archbishop) on Aug 09, 2010 at 00:32 UTC | |
by ikegami (Patriarch) on Aug 09, 2010 at 01:36 UTC | |
by Anonymous Monk on Aug 09, 2010 at 11:48 UTC | |
by ikegami (Patriarch) on Aug 09, 2010 at 13:59 UTC | |
|
Re^2: Calling a C function using malloc() in a XS
by Anonymous Monk on Aug 08, 2010 at 12:06 UTC | |
by Anonymous Monk on Aug 08, 2010 at 12:37 UTC |