[Kst] branches/work/kst/portto4/kst
Peter Kümmel
syntheticpp at gmx.net
Mon May 7 18:47:55 UTC 2012
SVN commit 1293422 by kuemmel:
read free memory on Windows
_WIN32_WINNT needed by mingw
M +3 -1 cmake/CMakeLists.txt
M +19 -7 src/libkst/datacollection.cpp
--- branches/work/kst/portto4/kst/cmake/CMakeLists.txt #1293421:1293422
@@ -183,8 +183,10 @@
endif()
+if(WIN32)
+ add_definitions(-D_WIN32_WINNT=0x0501) # Windows XP
+endif()
-
if(MSVC)
add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX)
else()
--- branches/work/kst/portto4/kst/src/libkst/datacollection.cpp #1293421:1293422
@@ -21,10 +21,14 @@
#include <stdlib.h>
#include <qapplication.h>
-
+#include "debug.h"
#include "sysinfo.h"
#include "psversion.h"
+#ifdef Q_OS_WIN
+#include <windows.h>
+#endif
+
namespace Kst {
static QMutex bigLock;
@@ -38,17 +42,25 @@
}
double Data::AvailableMemory() {
- double available_memory = 1024.0*1024.0*1024.0;
- // FIXME: under windows or mac, this is totally wrong.
- // Under windows, try GlobalMemoryStatusEx
+ double one_GB = 1024.0*1024.0*1024.0;
+ double available_memory = 0;
+
+#ifdef Q_OS_WIN
// (http://msdn.microsoft.com/en-us/library/aa366589)
- // but, I don't have access to a windows devel environment...
-
-#ifdef __linux__
+ MEMORYSTATUSEX statex;
+ statex.dwLength = sizeof(statex);
+ GlobalMemoryStatusEx(&statex);
+ available_memory = statex.ullAvailPhys;
+#elif Q_OS_LINUX
QMutexLocker ml(&bigLock);
meminfo();
available_memory = double(S(kb_main_free + kb_main_cached)) - 30.0*1024.0*1024.0; // 30MB margin
+#else
+ // TODO other OSs
+ // or assume 32-bit on a big system
+ available_memory = 4 * one_GB;
#endif
+ Debug::self()->log(QString("Available memory: %1 GB").arg(available_memory/one_GB));
return available_memory;
}
More information about the Kst
mailing list