Hi azaragoza,
Here's an Inline::C solution:
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;
The foo function simply prints the values to stdout.
The bar function returns the same values to an array.

Unfortunately, it works only with Microsoft compilers, but not MinGW. I don't know why GlobalMemoryStatusEx is inaccessible to MinGW - working out why should help fill in my day :-)

Cheers,
Rob

In reply to Re: How do I code GlobalMemoryStatusEx in perl by syphilis
in thread How do I code GlobalMemoryStatusEx in perl by azaragoza

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.