]> git.lizzy.rs Git - irrlicht.git/commitdiff
Fix COSOperator::getSystemMemory
authorsfan5 <sfan5@live.de>
Wed, 9 Mar 2022 21:39:25 +0000 (22:39 +0100)
committersfan5 <sfan5@live.de>
Wed, 9 Mar 2022 21:52:11 +0000 (22:52 +0100)
The values it returns are in Kilobytes and it was broken on macOS.

include/IOSOperator.h
source/Irrlicht/COSOperator.cpp

index 5d2d42aa6d7c14892b6815337f00f0bcb5b87c75..b195aed70b8afff63e35ae03cc93a6b9e9f339ca 100644 (file)
@@ -33,8 +33,8 @@ public:
        virtual const c8* getTextFromClipboard() const = 0;\r
 \r
        //! Get the total and available system RAM\r
-       /** \param totalBytes: will contain the total system memory in bytes\r
-       \param availableBytes: will contain the available memory in bytes\r
+       /** \param totalBytes: will contain the total system memory in Kilobytes (1024 B)\r
+       \param availableBytes: will contain the available memory in Kilobytes (1024 B)\r
        \return True if successful, false if not */\r
        virtual bool getSystemMemory(u32* totalBytes, u32* availableBytes) const = 0;\r
 \r
index a6f9461d8a253a4eede0d8b0b481620599da5786..25b04ad88821285830da66cfc563ab6597e61dc5 100644 (file)
@@ -163,24 +163,19 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
                *Avail = (u32)(MemoryStatusEx.ullAvailPhys>>10);\r
        return true;\r
 \r
-#elif defined(_IRR_POSIX_API_) && !defined(__FreeBSD__)\r
-#if defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)\r
+#elif defined(_IRR_POSIX_API_) && defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)\r
         long ps = sysconf(_SC_PAGESIZE);\r
         long pp = sysconf(_SC_PHYS_PAGES);\r
         long ap = sysconf(_SC_AVPHYS_PAGES);\r
 \r
-       if ((ps==-1)||(pp==-1)||(ap==-1))\r
+       if (ps == -1 || (Total && pp == -1) || (Avail && ap == -1))\r
                return false;\r
 \r
        if (Total)\r
-               *Total = (u32)((ps*(long long)pp)>>10);\r
+               *Total = (u32)((pp>>10)*ps);\r
        if (Avail)\r
-               *Avail = (u32)((ps*(long long)ap)>>10);\r
+               *Avail = (u32)((ap>>10)*ps);\r
        return true;\r
-#else\r
-       // TODO: implement for non-availability of symbols/features\r
-       return false;\r
-#endif\r
 #elif defined(_IRR_OSX_PLATFORM_)\r
        int mib[2];\r
        int64_t physical_memory;\r
@@ -191,6 +186,11 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
        mib[1] = HW_MEMSIZE;\r
        length = sizeof(int64_t);\r
        sysctl(mib, 2, &physical_memory, &length, NULL, 0);\r
+\r
+       if (Total)\r
+               *Total = (u32)(physical_memory>>10);\r
+       if (Avail)\r
+               *Avail = (u32)(physical_memory>>10); // we don't know better\r
        return true;\r
 #else\r
        // TODO: implement for others\r