in reply to Re^2: Calling a C function using malloc() in a XS
in thread Calling a C function using malloc() in a XS
I've tried without "stdlib.h". The same result for both cases (malloc()/free() and New()/Safefree())
I aslo created a new MSVC6 project with the same code (perl paths included):
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" struct s { int field1; int field2; int field3; }; void do_simulation() { int i; struct s * m = (struct s*)malloc(10000000 * sizeof(struct s)); for (i=0; i<10000000; i++) { m[i].field1 = 0; m[i].field2 = 1; m[i].field3 = 2; } /* sleep for 5 seconds to be able to analyze memory usage sleep(5); free(m); /* sleep for 5 seconds to be able to see if memory is freed sleep(5); } int main(void) { do_simulation(); return 1; }
... and everithing works as it should: first 5 seconds the process uses 200+ MB (VM included), the last 5 seconds memory usage drops down to ~600 KB
|
|---|