Dear monks,
I have to write a XS module that does some simulations with a lot of data (an array of ~10.000.000 structures). The simplified code is:
#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 = (struct s*)malloc(10000000 * sizeof(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; } free(m); } MODULE = MyModule PACKAGE = MyModule void sim() CODE: do_simulation();
Everything builds without problems, but the memory isn't freed after the function call. If I call do_simulation() function from a simple CPP file in a MS VS project, all is O.K. and the memory is freed instantly after function call.
The platform: Win32 XP SP2, ActiveState Perl 5.6.1, MS VS 6.0
What do I wrong?
In reply to Calling a C function using malloc() in a XS by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |