Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[WIN] fix reporting system memory > 4GB. Need to use GlobalMemoryEx/M…

…EMORYSTATUSEX instead of GlobalMemory
  • Loading branch information...
commit ee1a1e2c428b5923da9c39f5a78bc9208e4f2047 1 parent 396fc2d
@CrystalP CrystalP authored
View
13 xbmc/GUIInfoManager.cpp
@@ -1393,21 +1393,22 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow)
case SYSTEM_USED_MEMORY_PERCENT:
case SYSTEM_TOTAL_MEMORY:
{
- MEMORYSTATUS stat;
- GlobalMemoryStatus(&stat);
- int iMemPercentFree = 100 - ((int)( 100.0f* (stat.dwTotalPhys - stat.dwAvailPhys)/stat.dwTotalPhys + 0.5f ));
+ MEMORYSTATUSEX stat;
+ stat.dwLength = sizeof(MEMORYSTATUSEX);
+ GlobalMemoryStatusEx(&stat);
+ int iMemPercentFree = 100 - ((int)( 100.0f* (stat.ullTotalPhys - stat.ullAvailPhys)/stat.ullTotalPhys + 0.5f ));
int iMemPercentUsed = 100 - iMemPercentFree;
if (info == SYSTEM_FREE_MEMORY)
- strLabel.Format("%luMB", (ULONG)(stat.dwAvailPhys/MB));
+ strLabel.Format("%luMB", (ULONG)(stat.ullAvailPhys/MB));
else if (info == SYSTEM_FREE_MEMORY_PERCENT)
strLabel.Format("%i%%", iMemPercentFree);
else if (info == SYSTEM_USED_MEMORY)
- strLabel.Format("%luMB", (ULONG)((stat.dwTotalPhys - stat.dwAvailPhys)/MB));
+ strLabel.Format("%luMB", (ULONG)((stat.ullTotalPhys - stat.ullAvailPhys)/MB));
else if (info == SYSTEM_USED_MEMORY_PERCENT)
strLabel.Format("%i%%", iMemPercentUsed);
else if (info == SYSTEM_TOTAL_MEMORY)
- strLabel.Format("%luMB", (ULONG)(stat.dwTotalPhys/MB));
+ strLabel.Format("%luMB", (ULONG)(stat.ullTotalPhys/MB));
}
break;
case SYSTEM_SCREEN_MODE:
View
9 xbmc/guilib/TextureBundleXPR.cpp
@@ -279,10 +279,11 @@ bool CTextureBundleXPR::LoadFile(const CStdString& Filename, CAutoTexBuffer& Unp
if (!buffer || !UnpackedBuf.Set((BYTE*)XPhysicalAlloc(file->second.UnpackedSize, MAXULONG_PTR, 128, PAGE_READWRITE)))
{ // failed due to lack of memory
#ifndef _LINUX
- MEMORYSTATUS stat;
- GlobalMemoryStatus(&stat);
- CLog::Log(LOGERROR, "Out of memory loading texture: %s (need %lu bytes, have %lu bytes)", name.c_str(),
- file->second.UnpackedSize + file->second.PackedSize, stat.dwAvailPhys);
+ MEMORYSTATUSEX stat;
+ stat.dwLength = sizeof(MEMORYSTATUSEX);
+ GlobalMemoryStatusEx(&stat);
+ CLog::Log(LOGERROR, "Out of memory loading texture: %s (need %lu bytes, have %"PRIu64" bytes)", name.c_str(),
+ file->second.UnpackedSize + file->second.PackedSize, stat.ullAvailPhys);
#elif defined(__APPLE__) || defined(__FreeBSD__)
CLog::Log(LOGERROR, "Out of memory loading texture: %s (need %d bytes)", name.c_str(),
file->second.UnpackedSize + file->second.PackedSize);
View
7 xbmc/interfaces/python/xbmcmodule/xbmcmodule.cpp
@@ -434,9 +434,10 @@ namespace PYXBMC
PyObject* XBMC_GetFreeMem(PyObject *self, PyObject *args)
{
- MEMORYSTATUS stat;
- GlobalMemoryStatus(&stat);
- return PyInt_FromLong( stat.dwAvailPhys / ( 1024 * 1024 ) );
+ MEMORYSTATUSEX stat;
+ stat.dwLength = sizeof(MEMORYSTATUSEX);
+ GlobalMemoryStatusEx(&stat);
+ return PyInt_FromLong( stat.ullAvailPhys / ( 1024 * 1024 ) );
}
// getCpuTemp() method
View
12 xbmc/linux/PlatformDefs.h
@@ -423,18 +423,18 @@ typedef struct _SECURITY_ATTRIBUTES {
#define _stat stat
// Memory
-typedef struct _MEMORYSTATUS
+typedef struct _MEMORYSTATUSEX
{
DWORD dwLength;
DWORD dwMemoryLoad;
uint64_t dwTotalPhys;
uint64_t dwAvailPhys;
- uint64_t dwTotalPageFile;
- uint64_t dwAvailPageFile;
- uint64_t dwTotalVirtual;
- uint64_t dwAvailVirtual;
-} MEMORYSTATUS, *LPMEMORYSTATUS;
+ uint64_t ullTotalPageFile;
+ uint64_t ullAvailPageFile;
+ uint64_t ullTotalVirtual;
+ uint64_t ullAvailVirtual;
+} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
// Common HRESULT values
#ifndef NOERROR
View
36 xbmc/linux/XSyncUtils.cpp
@@ -47,13 +47,12 @@ using namespace XbmcThreads;
static FILE* procMeminfoFP = NULL;
#endif
-void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
+void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
{
if (!lpBuffer)
return;
- memset(lpBuffer, 0, sizeof(MEMORYSTATUS));
- lpBuffer->dwLength = sizeof(MEMORYSTATUS);
+ memset(lpBuffer, 0, sizeof(MEMORYSTATUSEX));
#ifdef __APPLE__
uint64_t physmem;
@@ -63,7 +62,7 @@ void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
// Total physical memory.
if (sysctl(mib, miblen, &physmem, &len, NULL, 0) == 0 && len == sizeof (physmem))
- lpBuffer->dwTotalPhys = physmem;
+ lpBuffer->ullTotalPhys = physmem;
// Virtual memory.
mib[0] = CTL_VM; mib[1] = VM_SWAPUSAGE;
@@ -71,8 +70,8 @@ void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
len = sizeof(struct xsw_usage);
if (sysctl(mib, miblen, &swap, &len, NULL, 0) == 0)
{
- lpBuffer->dwAvailPageFile = swap.xsu_avail;
- lpBuffer->dwTotalVirtual = lpBuffer->dwTotalPhys + swap.xsu_total;
+ lpBuffer->ullAvailPageFile = swap.xsu_avail;
+ lpBuffer->ullTotalVirtual = lpBuffer->ullTotalPhys + swap.xsu_total;
}
// In use.
@@ -89,8 +88,8 @@ void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
{
uint64_t used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pageSize;
- lpBuffer->dwAvailPhys = lpBuffer->dwTotalPhys - used;
- lpBuffer->dwAvailVirtual = lpBuffer->dwAvailPhys; // FIXME.
+ lpBuffer->ullAvailPhys = lpBuffer->ullTotalPhys - used;
+ lpBuffer->ullAvailVirtual = lpBuffer->ullAvailPhys; // FIXME.
}
}
#elif defined(__FreeBSD__)
@@ -101,8 +100,8 @@ void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
/* physmem */
len = sizeof(physmem);
if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) == 0) {
- lpBuffer->dwTotalPhys = physmem;
- lpBuffer->dwTotalVirtual = physmem;
+ lpBuffer->ullTotalPhys = physmem;
+ lpBuffer->ullTotalVirtual = physmem;
}
/* pagesize */
len = sizeof(pagesize);
@@ -122,11 +121,11 @@ void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
mem_free *= pagesize;
/* mem_avail = mem_inactive + mem_cache + mem_free */
- lpBuffer->dwAvailPhys = mem_inactive + mem_cache + mem_free;
- lpBuffer->dwAvailVirtual = mem_inactive + mem_cache + mem_free;
+ lpBuffer->ullAvailPhys = mem_inactive + mem_cache + mem_free;
+ lpBuffer->ullAvailVirtual = mem_inactive + mem_cache + mem_free;
if (sysctlbyname("vm.stats.vm.v_swappgsout", &swap_free, &len, NULL, 0) == 0)
- lpBuffer->dwAvailPageFile = swap_free * pagesize;
+ lpBuffer->ullAvailPageFile = swap_free * pagesize;
#else
struct sysinfo info;
char name[32];
@@ -159,12 +158,11 @@ void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
rewind(procMeminfoFP);
fflush(procMeminfoFP);
}
- lpBuffer->dwLength = sizeof(MEMORYSTATUS);
- lpBuffer->dwAvailPageFile = (info.freeswap * info.mem_unit);
- lpBuffer->dwAvailPhys = ((info.freeram + info.bufferram) * info.mem_unit);
- lpBuffer->dwAvailVirtual = ((info.freeram + info.bufferram) * info.mem_unit);
- lpBuffer->dwTotalPhys = (info.totalram * info.mem_unit);
- lpBuffer->dwTotalVirtual = (info.totalram * info.mem_unit);
+ lpBuffer->ullAvailPageFile = (info.freeswap * info.mem_unit);
+ lpBuffer->ullAvailPhys = ((info.freeram + info.bufferram) * info.mem_unit);
+ lpBuffer->ullAvailVirtual = ((info.freeram + info.bufferram) * info.mem_unit);
+ lpBuffer->ullTotalPhys = (info.totalram * info.mem_unit);
+ lpBuffer->ullTotalVirtual = (info.totalram * info.mem_unit);
#endif
}
View
2  xbmc/linux/XSyncUtils.h
@@ -36,7 +36,7 @@
#define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 )
#define WAIT_ABANDONED_0 ((STATUS_ABANDONED_WAIT_0 ) + 0 )
-void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer);
+void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer);
#endif
View
11 xbmc/windows/GUIWindowDebugInfo.cpp
@@ -97,17 +97,18 @@ void CGUIWindowDebugInfo::Process(unsigned int currentTime, CDirtyRegionList &di
CStdString info;
if (LOG_LEVEL_DEBUG_FREEMEM <= g_advancedSettings.m_logLevel)
{
- MEMORYSTATUS stat;
- GlobalMemoryStatus(&stat);
+ MEMORYSTATUSEX stat;
+ stat.dwLength = sizeof(MEMORYSTATUSEX);
+ GlobalMemoryStatusEx(&stat);
CStdString profiling = CGUIControlProfiler::IsRunning() ? " (profiling)" : "";
CStdString strCores = g_cpuInfo.GetCoresUsageString();
#if !defined(_LINUX)
- info.Format("LOG: %sxbmc.log\nMEM: %d/%d KB - FPS: %2.1f fps\nCPU: %s%s", g_settings.m_logFolder.c_str(),
- stat.dwAvailPhys/1024, stat.dwTotalPhys/1024, g_infoManager.GetFPS(), strCores.c_str(), profiling.c_str());
+ info.Format("LOG: %sxbmc.log\nMEM: %"PRIu64"/%"PRIu64" KB - FPS: %2.1f fps\nCPU: %s%s", g_settings.m_logFolder.c_str(),
+ stat.ullAvailPhys/1024, stat.ullTotalPhys/1024, g_infoManager.GetFPS(), strCores.c_str(), profiling.c_str());
#else
double dCPU = m_resourceCounter.GetCPUUsage();
info.Format("LOG: %sxbmc.log\nMEM: %"PRIu64"/%"PRIu64" KB - FPS: %2.1f fps\nCPU: %s (CPU-XBMC %4.2f%%%s)", g_settings.m_logFolder.c_str(),
- stat.dwAvailPhys/1024, stat.dwTotalPhys/1024, g_infoManager.GetFPS(), strCores.c_str(), dCPU, profiling.c_str());
+ stat.ullAvailPhys/1024, stat.ullTotalPhys/1024, g_infoManager.GetFPS(), strCores.c_str(), dCPU, profiling.c_str());
#endif
}
Please sign in to comment.
Something went wrong with that request. Please try again.