Make memory menu items 64-bit safe.

Redo the precision levels of various calculations in the memory bar items
so they don't overflow on systems with > 4GB of RAM. Previously one could
see fun results like the kernel using negative amounts of memory on such
systems.
This commit is contained in:
Rene Gollent
2012-04-30 21:56:30 -04:00
parent 119c90fc35
commit aa19448875
4 changed files with 52 additions and 52 deletions
@@ -39,9 +39,9 @@ KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info& systemInfo)
fLastSum = -1; fLastSum = -1;
fGrenze1 = -1; fGrenze1 = -1;
fGrenze2 = -1; fGrenze2 = -1;
fPhysicalMemory = float(int(systemInfo.max_pages * B_PAGE_SIZE / 1024)); fPhysicalMemory = systemInfo.max_pages * B_PAGE_SIZE / 1024LL;
fCommittedMemory = float(int(systemInfo.used_pages * B_PAGE_SIZE / 1024)); fCommittedMemory = systemInfo.used_pages * B_PAGE_SIZE / 1024LL;
fCachedMemory = float(int(systemInfo.cached_pages * B_PAGE_SIZE / 1024)); fCachedMemory = systemInfo.cached_pages * B_PAGE_SIZE / 1024LL;
} }
@@ -55,8 +55,8 @@ KernelMemoryBarMenuItem::DrawContent()
void void
KernelMemoryBarMenuItem::UpdateSituation(float committedMemory, KernelMemoryBarMenuItem::UpdateSituation(int64 committedMemory,
float cachedMemory) int64 cachedMemory)
{ {
fCommittedMemory = committedMemory; fCommittedMemory = committedMemory;
fCachedMemory = cachedMemory; fCachedMemory = cachedMemory;
@@ -87,9 +87,9 @@ KernelMemoryBarMenuItem::DrawBar(bool force)
cadre.InsetBy(1, 1); cadre.InsetBy(1, 1);
BRect r = cadre; BRect r = cadre;
float grenze1 = cadre.left + (cadre.right - cadre.left) double grenze1 = cadre.left + (cadre.right - cadre.left)
* fCachedMemory / fPhysicalMemory; * fCachedMemory / fPhysicalMemory;
float grenze2 = cadre.left + (cadre.right - cadre.left) double grenze2 = cadre.left + (cadre.right - cadre.left)
* fCommittedMemory / fPhysicalMemory; * fCommittedMemory / fPhysicalMemory;
if (grenze1 > cadre.right) if (grenze1 > cadre.right)
grenze1 = cadre.right; grenze1 = cadre.right;
@@ -1,20 +1,20 @@
/* /*
ProcessController @ 2000, Georges-Edouard Berenger, All Rights Reserved. ProcessController @ 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _KERNEL_MEMORY_BAR_MENU_ITEM_H_ #ifndef _KERNEL_MEMORY_BAR_MENU_ITEM_H_
#define _KERNEL_MEMORY_BAR_MENU_ITEM_H_ #define _KERNEL_MEMORY_BAR_MENU_ITEM_H_
@@ -30,15 +30,15 @@ class KernelMemoryBarMenuItem : public BMenuItem {
virtual void GetContentSize(float* _width, float* _height); virtual void GetContentSize(float* _width, float* _height);
void DrawBar(bool force); void DrawBar(bool force);
void UpdateSituation(float committedMemory, float fCachedMemory); void UpdateSituation(int64 committedMemory, int64 fCachedMemory);
private: private:
float fCachedMemory; int64 fCachedMemory;
float fPhysicalMemory; int64 fPhysicalMemory;
float fCommittedMemory; int64 fCommittedMemory;
double fLastSum; double fLastSum;
float fGrenze1; double fGrenze1;
float fGrenze2; double fGrenze2;
}; };
#endif // _KERNEL_MEMORY_BAR_MENU_ITEM_H_ #endif // _KERNEL_MEMORY_BAR_MENU_ITEM_H_
@@ -135,8 +135,8 @@ MemoryBarMenuItem::DrawBar(bool force)
rect.InsetBy(1, 1); rect.InsetBy(1, 1);
BRect r = rect; BRect r = rect;
float grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory) / fCommitedMemory; double grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory) / fCommitedMemory;
float grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory) / fCommitedMemory; double grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory) / fCommitedMemory;
if (grenze1 > rect.right) if (grenze1 > rect.right)
grenze1 = rect.right; grenze1 = rect.right;
if (grenze2 > rect.right) if (grenze2 > rect.right)
@@ -234,7 +234,7 @@ MemoryBarMenuItem::GetContentSize(float* _width, float* _height)
int int
MemoryBarMenuItem::UpdateSituation(int commitedMemory) MemoryBarMenuItem::UpdateSituation(int64 commitedMemory)
{ {
fCommitedMemory = commitedMemory; fCommitedMemory = commitedMemory;
BarUpdate(); BarUpdate();
@@ -247,8 +247,8 @@ MemoryBarMenuItem::BarUpdate()
{ {
area_info areaInfo; area_info areaInfo;
int32 cookie = 0; int32 cookie = 0;
size_t lram_size = 0; int64 lram_size = 0;
size_t lwram_size = 0; int64 lwram_size = 0;
bool exists = false; bool exists = false;
while (get_next_area_info(fTeamID, &cookie, &areaInfo) == B_OK) { while (get_next_area_info(fTeamID, &cookie, &areaInfo) == B_OK) {
+22 -22
View File
@@ -1,20 +1,20 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _MEMORY_BAR_MENU_ITEM_H_ #ifndef _MEMORY_BAR_MENU_ITEM_H_
#define _MEMORY_BAR_MENU_ITEM_H_ #define _MEMORY_BAR_MENU_ITEM_H_
@@ -36,23 +36,23 @@ class MemoryBarMenuItem : public BMenuItem {
void DrawIcon(); void DrawIcon();
void DrawBar(bool force); void DrawBar(bool force);
int UpdateSituation(int commitedMemory); int UpdateSituation(int64 commitedMemory);
void BarUpdate(); void BarUpdate();
void Init(); void Init();
void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon); void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
private: private:
int fPhysicalMemory; int64 fPhysicalMemory;
int fCommitedMemory; int64 fCommitedMemory;
int fWriteMemory; int64 fWriteMemory;
int fAllMemory; int64 fAllMemory;
int fLastCommited; int64 fLastCommited;
int fLastWrite; int64 fLastWrite;
int fLastAll; int64 fLastAll;
team_id fTeamID; team_id fTeamID;
BBitmap* fIcon; BBitmap* fIcon;
float fGrenze1; double fGrenze1;
float fGrenze2; double fGrenze2;
bool fDeleteIcon; bool fDeleteIcon;
}; };