aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/COSOperator.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-03-09 22:39:25 +0100
committersfan5 <sfan5@live.de>2022-03-09 22:52:11 +0100
commite469c54f76f6d24f92389b4e8a27b9cce7152888 (patch)
tree2a74107ba34c173df9b4b2f353b25167e384e53d /source/Irrlicht/COSOperator.cpp
parentdf908ef4eaa7fd3292faa34d690edce40106da3c (diff)
downloadirrlicht-e469c54f76f6d24f92389b4e8a27b9cce7152888.tar.xz
Fix COSOperator::getSystemMemory
The values it returns are in Kilobytes and it was broken on macOS.
Diffstat (limited to 'source/Irrlicht/COSOperator.cpp')
-rw-r--r--source/Irrlicht/COSOperator.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp
index a6f9461..25b04ad 100644
--- a/source/Irrlicht/COSOperator.cpp
+++ b/source/Irrlicht/COSOperator.cpp
@@ -163,24 +163,19 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
*Avail = (u32)(MemoryStatusEx.ullAvailPhys>>10);
return true;
-#elif defined(_IRR_POSIX_API_) && !defined(__FreeBSD__)
-#if defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
+#elif defined(_IRR_POSIX_API_) && defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
long ps = sysconf(_SC_PAGESIZE);
long pp = sysconf(_SC_PHYS_PAGES);
long ap = sysconf(_SC_AVPHYS_PAGES);
- if ((ps==-1)||(pp==-1)||(ap==-1))
+ if (ps == -1 || (Total && pp == -1) || (Avail && ap == -1))
return false;
if (Total)
- *Total = (u32)((ps*(long long)pp)>>10);
+ *Total = (u32)((pp>>10)*ps);
if (Avail)
- *Avail = (u32)((ps*(long long)ap)>>10);
+ *Avail = (u32)((ap>>10)*ps);
return true;
-#else
- // TODO: implement for non-availability of symbols/features
- return false;
-#endif
#elif defined(_IRR_OSX_PLATFORM_)
int mib[2];
int64_t physical_memory;
@@ -191,6 +186,11 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
mib[1] = HW_MEMSIZE;
length = sizeof(int64_t);
sysctl(mib, 2, &physical_memory, &length, NULL, 0);
+
+ if (Total)
+ *Total = (u32)(physical_memory>>10);
+ if (Avail)
+ *Avail = (u32)(physical_memory>>10); // we don't know better
return true;
#else
// TODO: implement for others