Jim Michaels писал 2013-11-18 01:12:
> what's going on? GlobalMemoryStatusEx() always returns failure. I even
> memset() the struct with 0's, no difference.
> 
> 
> #include <iostream>
> #Include <memory.h>
> #include <windows.h>
> #include <stdint.h>
> #include <WinBase.h>
> 
> 
> typedef uint64_t addressType; //with 64-bit boxes, there may be
> support for __int128, but I guess not yet with some compilers
> typedef uint64_t vecElementType;
> MEMORYSTATUSEX mse;
> 
> addressType availableRAM(void) {
>     memset(&mse,0, sizeof(MEMORYSTATUSEX));
>     if (0==GlobalMemoryStatusEx(&mse)) {
>         std::cout<<"GlobalMemoryStatusEx():ERROR\n";
>         return 0;
>     }
>     addressType ram=mse.ullAvailPhys;
>     std::cout<<"availableRam()="<<ram<<"\n";
>     return ram; //do I need to use a percentage here? is there a
> structure overhead with bitset?
> }
> int main(int argc, char * argv[]) {
>     UINT_TYPE n=0;
>     size_t sp,ep;
> 
>     availRam = availableRAM();
>     if (0!=availRam) {
>         availRam -= RESERVE_RAM;//2*2^30. we reserve 2GiB for
> applications to run fast like browsers etc
>     }
>     return 0;
> }

Your code is wrong.
Just now I have compiled and executed the code I got from MSDN site.

//  Sample output:
//  There is       51 percent of memory in use.
//  There are 2029968 total KB of physical memory.
//  There are  987388 free  KB of physical memory.
//  There are 3884620 total KB of paging file.
//  There are 2799776 free  KB of paging file.
//  There are 2097024 total KB of virtual memory.
//  There are 2084876 free  KB of virtual memory.
//  There are       0 free  KB of extended memory.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

// Use to convert bytes to KB
#define DIV 1024

// Specify the width of the field in which to print the numbers.
// The asterisk in the format specifier "%*I64d" takes an integer
// argument and uses it to pad and right justify the number.
#define WIDTH 11

int main() {
   MEMORYSTATUSEX statex;

   statex.dwLength = sizeof (statex);

   GlobalMemoryStatusEx (&statex);

   _tprintf (TEXT("There is  %*ld percent of memory in use.\n"),
             WIDTH, statex.dwMemoryLoad);
   _tprintf (TEXT("There are %*I64d total KB of physical memory.\n"),
             WIDTH, statex.ullTotalPhys/DIV);
   _tprintf (TEXT("There are %*I64d free  KB of physical memory.\n"),
             WIDTH, statex.ullAvailPhys/DIV);
   _tprintf (TEXT("There are %*I64d total KB of paging file.\n"),
             WIDTH, statex.ullTotalPageFile/DIV);
   _tprintf (TEXT("There are %*I64d free  KB of paging file.\n"),
             WIDTH, statex.ullAvailPageFile/DIV);
   _tprintf (TEXT("There are %*I64d total KB of virtual memory.\n"),
             WIDTH, statex.ullTotalVirtual/DIV);
   _tprintf (TEXT("There are %*I64d free  KB of virtual memory.\n"),
             WIDTH, statex.ullAvailVirtual/DIV);

   // Show the amount of extended memory available.

   _tprintf (TEXT("There are %*I64d free  KB of extended memory.\n"),
             WIDTH, statex.ullAvailExtendedVirtual/DIV);
}




-- 
Regards, niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingw-w64/
___________________________________________________
Another online IDE: http://liveworkspace.org/

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to