The foo function simply prints the values to stdout.use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; #define _WIN32_WINNT 0x0500 #include <windows.h> #define DIV 1024 char *divisor = "K"; #define WIDTH 7 void foo() { MEMORYSTATUSEX statex; statex.dwLength = sizeof (statex); GlobalMemoryStatusEx (&statex); printf ("%ld percent of memory is in use.\n", statex.dwMemoryLoad); printf ("There are %*I64d total %sbytes of physical memory.\n", WIDTH, statex.ullTotalPhys/DIV, divisor); printf ("There are %*I64d free %sbytes of physical memory.\n", WIDTH, statex.ullAvailPhys/DIV, divisor); printf ("There are %*I64d total %sbytes of paging file.\n", WIDTH, statex.ullTotalPageFile/DIV, divisor); printf ("There are %*I64d free %sbytes of paging file.\n", WIDTH, statex.ullAvailPageFile/DIV, divisor); printf ("There are %*I64d total %sbytes of virtual memory.\n", WIDTH, statex.ullTotalVirtual/DIV, divisor); printf ("There are %*I64d free %sbytes of virtual memory.\n", WIDTH, statex.ullAvailVirtual/DIV, divisor); // Show the amount of extended memory available. printf ("There are %*I64x free %sbytes of extended memory.\n", WIDTH, statex.ullAvailExtendedVirtual/DIV, divisor); } void bar() { Inline_Stack_Vars; MEMORYSTATUSEX statex; char buffer [30]; statex.dwLength = sizeof (statex); GlobalMemoryStatusEx (&statex); Inline_Stack_Reset; Inline_Stack_Push(sv_2mortal(newSVuv(statex.dwMemoryLoad))); _ui64toa(statex.ullTotalPhys/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); _ui64toa(statex.ullAvailPhys/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); _ui64toa(statex.ullTotalPageFile/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); _ui64toa(statex.ullAvailPageFile/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); _ui64toa(statex.ullTotalVirtual/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); _ui64toa(statex.ullAvailVirtual/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); _ui64toa(statex.ullAvailExtendedVirtual/DIV, buffer, 10); Inline_Stack_Push(sv_2mortal(newSVpv(buffer, 0))); Inline_Stack_Done; Inline_Stack_Return(8); } EOC foo(); @info = bar(); print "\n"; print "$_\n" for @info;
In reply to Re: How do I code GlobalMemoryStatusEx in perl
by syphilis
in thread How do I code GlobalMemoryStatusEx in perl
by azaragoza
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |