forked from Mirrorlandia_minetest/irrlicht
Fix COSOperator::getSystemMemory
The values it returns are in Kilobytes and it was broken on macOS.
This commit is contained in:
parent
df908ef4ea
commit
e469c54f76
@ -33,8 +33,8 @@ public:
|
|||||||
virtual const c8* getTextFromClipboard() const = 0;
|
virtual const c8* getTextFromClipboard() const = 0;
|
||||||
|
|
||||||
//! Get the total and available system RAM
|
//! Get the total and available system RAM
|
||||||
/** \param totalBytes: will contain the total system memory in bytes
|
/** \param totalBytes: will contain the total system memory in Kilobytes (1024 B)
|
||||||
\param availableBytes: will contain the available memory in bytes
|
\param availableBytes: will contain the available memory in Kilobytes (1024 B)
|
||||||
\return True if successful, false if not */
|
\return True if successful, false if not */
|
||||||
virtual bool getSystemMemory(u32* totalBytes, u32* availableBytes) const = 0;
|
virtual bool getSystemMemory(u32* totalBytes, u32* availableBytes) const = 0;
|
||||||
|
|
||||||
|
@ -163,24 +163,19 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
|
|||||||
*Avail = (u32)(MemoryStatusEx.ullAvailPhys>>10);
|
*Avail = (u32)(MemoryStatusEx.ullAvailPhys>>10);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
#elif defined(_IRR_POSIX_API_) && !defined(__FreeBSD__)
|
#elif defined(_IRR_POSIX_API_) && defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
|
||||||
#if defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
|
|
||||||
long ps = sysconf(_SC_PAGESIZE);
|
long ps = sysconf(_SC_PAGESIZE);
|
||||||
long pp = sysconf(_SC_PHYS_PAGES);
|
long pp = sysconf(_SC_PHYS_PAGES);
|
||||||
long ap = sysconf(_SC_AVPHYS_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;
|
return false;
|
||||||
|
|
||||||
if (Total)
|
if (Total)
|
||||||
*Total = (u32)((ps*(long long)pp)>>10);
|
*Total = (u32)((pp>>10)*ps);
|
||||||
if (Avail)
|
if (Avail)
|
||||||
*Avail = (u32)((ps*(long long)ap)>>10);
|
*Avail = (u32)((ap>>10)*ps);
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
// TODO: implement for non-availability of symbols/features
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
#elif defined(_IRR_OSX_PLATFORM_)
|
#elif defined(_IRR_OSX_PLATFORM_)
|
||||||
int mib[2];
|
int mib[2];
|
||||||
int64_t physical_memory;
|
int64_t physical_memory;
|
||||||
@ -191,6 +186,11 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
|
|||||||
mib[1] = HW_MEMSIZE;
|
mib[1] = HW_MEMSIZE;
|
||||||
length = sizeof(int64_t);
|
length = sizeof(int64_t);
|
||||||
sysctl(mib, 2, &physical_memory, &length, NULL, 0);
|
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;
|
return true;
|
||||||
#else
|
#else
|
||||||
// TODO: implement for others
|
// TODO: implement for others
|
||||||
|
Loading…
Reference in New Issue
Block a user