in reply to Re: Calling a C function using malloc() in a XS
in thread Calling a C function using malloc() in a XS
For me (perl-5.12.0, Win32) the memory is freed as soon as free/Safefree is called.use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; 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; } printf("Sleeping for 5\n"); sleep(5); free(m); printf("Memory freed ... sleep for another 5\n"); sleep(5); printf("Done\n"); } void do_simulation2() { int i; struct s* m; New(1, (struct s*)m, 10000000, struct s); for ( i=0; i<10000000; i++ ) { m[i].field1 = 0; m[i].field2 = 1; m[i].field3 = 2; } printf("Sleeping for 5\n"); sleep(5); Safefree(m); printf("Memory freed ... sleep for another 5\n"); sleep(5); printf("Done\n"); } EOC do_simulation(); do_simulation2();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Calling a C function using malloc() in a XS
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 |