2
0
Эх сурвалжийг харах

GetTotalMemory(), which returns the total amount of useable memory.

Florastamine 8 жил өмнө
parent
commit
c7981ecad1

+ 1 - 0
Docs/AngelScriptAPI.h

@@ -15944,6 +15944,7 @@ Array<String> GetObjectsByCategory(const String&);
 String GetParentPath(const String&);
 String GetPath(const String&);
 String GetPlatform();
+uint64 GetTotalMemory();
 uint GetRG16Format();
 uint GetRGBA16Format();
 uint GetRGBAFloat16Format();

+ 1 - 0
Docs/LuaScriptAPI.dox

@@ -8654,6 +8654,7 @@ Properties:
 - String GetParentPath(const String pathName)
 - String GetPath(const String fullPath)
 - String GetPlatform()
+- unsigned long long GetTotalMemory()
 - unsigned GetRandomSeed()
 - Renderer* GetRenderer()
 - Time* GetTime()

+ 1 - 0
Docs/ScriptAPI.dox

@@ -16521,6 +16521,7 @@ Properties:
 - String GetParentPath(const String&)
 - String GetPath(const String&)
 - String GetPlatform()
+- uint64 GetTotalMemory() 
 - uint GetRG16Format()
 - uint GetRGBA16Format()
 - uint GetRGBAFloat16Format()

+ 1 - 0
Source/Urho3D/AngelScript/CoreAPI.cpp

@@ -829,6 +829,7 @@ static void RegisterProcessUtils(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("uint GetNumLogicalCPUs()", asFUNCTION(GetNumLogicalCPUs), asCALL_CDECL);
     engine->RegisterGlobalFunction("void SetMiniDumpDir(const String&in)", asFUNCTION(SetMiniDumpDir), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetMiniDumpDir()", asFUNCTION(GetMiniDumpDir), asCALL_CDECL);
+    engine->RegisterGlobalFunction("uint64 GetTotalMemory()", asFUNCTION(GetTotalMemory), asCALL_CDECL);
 }
 
 static void ConstructAttributeInfo(AttributeInfo* ptr)

+ 17 - 0
Source/Urho3D/Core/ProcessUtils.cpp

@@ -47,6 +47,7 @@
 #endif
 #else
 #include <unistd.h>
+#include <sys/sysinfo.h>
 #endif
 
 #if defined(__EMSCRIPTEN__) && defined(__EMSCRIPTEN_PTHREADS__)
@@ -485,4 +486,20 @@ String GetMiniDumpDir()
     return miniDumpDir;
 }
 
+unsigned long long GetTotalMemory()
+{
+#if defined(__linux__)
+    struct sysinfo s;
+    if(sysinfo(&s) != -1)
+        return s.totalram; 
+#elif defined(_WIN32)
+    MEMORYSTATUSEX state; 
+    state.dwLength = sizeof(state); 
+    if(GlobalMemoryStatusEx(&state)) 
+        return state.ullTotalPhys; 
+#else 
+#endif 
+    return 0ull;
+}
+
 }

+ 2 - 1
Source/Urho3D/Core/ProcessUtils.h

@@ -69,5 +69,6 @@ URHO3D_API unsigned GetNumLogicalCPUs();
 URHO3D_API void SetMiniDumpDir(const String& pathName);
 /// Return minidump write location.
 URHO3D_API String GetMiniDumpDir();
-
+/// Return the total amount of useable memory. 
+URHO3D_API unsigned long long GetTotalMemory(); 
 }

+ 2 - 0
Source/Urho3D/LuaScript/pkgs/Core/ProcessUtils.pkg

@@ -15,3 +15,5 @@ unsigned GetNumLogicalCPUs();
 
 void SetMiniDumpDir(const String pathName);
 String GetMiniDumpDir();
+
+unsigned long long GetTotalMemory();