#! 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", GetLastError() ); 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