From fab89241b24afdfdf7c9d77b85b5f9ff0bbca1c9 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sat, 18 Dec 2010 01:07:33 +0000 Subject: [PATCH] Implement memory functions for freebsd Patch by Alberto Villa BUGS: 218418 svn path=/trunk/KDE/kdegraphics/okular/; revision=1207422 --- core/document.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/core/document.cpp b/core/document.cpp index fefeeb8d4..a18c87d9f 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -14,6 +14,10 @@ #ifdef Q_OS_WIN #define _WIN32_WINNT 0x0500 #include +#elif defined(Q_OS_FREEBSD) +#include +#include +#include #endif // qt/kde/system includes @@ -248,6 +252,12 @@ qulonglong DocumentPrivate::getTotalMemory() if ( entry.startsWith( "MemTotal:" ) ) return (cachedValue = (Q_UINT64_C(1024) * entry.section( ' ', -2, -2 ).toULongLong())); } +#elif defined(Q_OS_FREEBSD) + qulonglong physmem; + int mib[] = {CTL_HW, HW_PHYSMEM}; + size_t len = sizeof( physmem ); + if ( sysctl( mib, 2, &physmem, &len, NULL, 0 ) == 0 ) + return (cachedValue = physmem); #elif defined(Q_OS_WIN) MEMORYSTATUSEX stat; stat.dwLength = sizeof(stat); @@ -294,6 +304,26 @@ qulonglong DocumentPrivate::getFreeMemory() lastUpdate = QTime::currentTime(); return ( cachedValue = (Q_UINT64_C(1024) * memoryFree) ); +#elif defined(Q_OS_FREEBSD) + qulonglong cache, inact, free, psize; + size_t cachelen, inactlen, freelen, psizelen; + cachelen = sizeof( cache ); + inactlen = sizeof( inact ); + freelen = sizeof( free ); + psizelen = sizeof( psize ); + // sum up inactive, cached and free memory + if ( sysctlbyname( "vm.stats.vm.v_cache_count", &cache, &cachelen, NULL, 0 ) == 0 && + sysctlbyname( "vm.stats.vm.v_inactive_count", &inact, &inactlen, NULL, 0 ) == 0 && + sysctlbyname( "vm.stats.vm.v_free_count", &free, &freelen, NULL, 0 ) == 0 && + sysctlbyname( "vm.stats.vm.v_page_size", &psize, &psizelen, NULL, 0 ) == 0 ) + { + lastUpdate = QTime::currentTime(); + return (cachedValue = (cache + inact + free) * psize); + } + else + { + return 0; + } #elif defined(Q_OS_WIN) MEMORYSTATUSEX stat; stat.dwLength = sizeof(stat);