COSOperator::getSystemMemory now returns some value on OSX. Also it's kb not bytes.

Before the value was checked, but not put into the return variables.
Header update to show that information in kb not bytes (on all systems, was just documented wrong)
Some cleanup of code.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6369 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2022-05-02 15:19:37 +00:00
parent d19d6939d4
commit 296824e8b6
3 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,8 @@
--------------------------
Changes in 1.9 (not yet released)
- COSOperator::getSystemMemory now returns some value on OSX (thought same for total and available).
Thanks @sfan5 for patch https://irrlicht.sourceforge.io/forum/viewtopic.php?f=2&t=52819 and https://github.com/minetest/irrlicht/commit/e469c54f76f6d24f92389b4e8a27b9cce7152888
- Fix CVertexBuffer::setType switching types for non-empty arrays. Before we had some bad casts which could result in random initializing of some vertex data.
- IVertexBuffer interface changes: pointer() now returns void*. Adding a const version of getData(). Some set functions have now overload for all vertex types.
- S3DVertex now always initializes color to 0xffffff. That was previously the only uninitialized variable in there. Also both derived classes have now a constructor taking a const S3DVertex&.

View File

@ -38,8 +38,8 @@ public:
virtual bool getProcessorSpeedMHz(u32* MHz) const = 0;
//! Get the total and available system RAM
/** \param totalBytes: will contain the total system memory in bytes
\param availableBytes: will contain the available memory in bytes
/** \param totalBytes: will contain the total system memory in Kilobytes (1024 B)
\param availableBytes: will contain the available memory in Kilobytes (1024 B)
\return True if successful, false if not */
virtual bool getSystemMemory(u32* totalBytes, u32* availableBytes) const = 0;

View File

@ -239,24 +239,19 @@ bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
return true;
#endif
#elif defined(_IRR_POSIX_API_) && !defined(__FreeBSD__)
#if 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);
#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;
@ -267,6 +262,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