1 /* Copyright (C) 2005-2011 Fabio Riccardi */
2 
3 // standard
4 #include <cstring>
5 
6 // windows
7 #include <windows.h>
8 #include <winbase.h>
9 
10 // local
11 #include "LC_JNIUtils.h"
12 #include "LC_WinError.h"
13 #ifndef AUTO_DEP
14 #include "javah/com_lightcrafts_platform_windows_WindowsMemory.h"
15 #endif
16 
17 using namespace std;
18 
19 ////////// JNI ////////////////////////////////////////////////////////////////
20 
21 #define WindowsMemory_METHOD(method) \
22         name4(Java_,com_lightcrafts_platform_windows_WindowsMemory,_,method)
23 
24 /**
25  * Gets the amount of physical memory installed in the computer in MB.
26  */
WindowsMemory_METHOD(getPhysicalMemoryInMB)27 JNIEXPORT jint JNICALL WindowsMemory_METHOD(getPhysicalMemoryInMB)
28     ( JNIEnv *env, jclass )
29 {
30     MEMORYSTATUSEX ms;
31     ::memset( &ms, 0, sizeof ms );
32     ms.dwLength = sizeof ms;
33     if ( !::GlobalMemoryStatusEx( &ms ) ) {
34         LC_throwIllegalStateException( env,
35             LC_formatError( "GlobalMemoryStatusEx()", ::GetLastError() )
36         );
37         return 0;
38     }
39     return static_cast<jint>( ms.ullTotalPhys / 1048576 );
40 }
41 /* vim:set et sw=4 ts=4: */
42