in reply to Calling a C function using malloc() in a XS

If you really need to do this, then go to the OS direct for the memory and you can guarantee to be able to give it back when you're done with it:

#! perl -slw use 5.010; use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'FreeMem', CLEAN_AFTER_BUILD => 0; struct s { int field1; int field2; int field3; }; #define SIZE ((int)10e6 * sizeof( struct s )) int test( SV *dummy ) { char buf[256]; struct s *m; printf( "CheckMem then enter"); gets( buf ); m= VirtualAlloc( NULL, SIZE, MEM_COMMIT, PAGE_READWRITE ); if( !m ) croak( "Couldn't allocate virtual memory: %d\n", GetLastE +rror() ); printf( "CheckMem then enter"); gets( buf ); VirtualFree( m, SIZE, MEM_DECOMMIT ); printf( "CheckMem then enter"); gets( buf ); return 1; } END_C test( 1 ); __END__ C:\test>freeMem-IC.pl CheckMem then enter 7.5MB CheckMem then enter 122.1MB CheckMem then enter 7.7MB

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy