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

View File

@ -39,9 +39,9 @@ KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info& systemInfo)
fLastSum = -1;
fGrenze1 = -1;
fGrenze2 = -1;
fPhysicalMemory = float(int(systemInfo.max_pages * B_PAGE_SIZE / 1024));
fCommittedMemory = float(int(systemInfo.used_pages * B_PAGE_SIZE / 1024));
fCachedMemory = float(int(systemInfo.cached_pages * B_PAGE_SIZE / 1024));
fPhysicalMemory = systemInfo.max_pages * B_PAGE_SIZE / 1024LL;
fCommittedMemory = systemInfo.used_pages * B_PAGE_SIZE / 1024LL;
fCachedMemory = systemInfo.cached_pages * B_PAGE_SIZE / 1024LL;
}
@ -55,8 +55,8 @@ KernelMemoryBarMenuItem::DrawContent()
void
KernelMemoryBarMenuItem::UpdateSituation(float committedMemory,
float cachedMemory)
KernelMemoryBarMenuItem::UpdateSituation(int64 committedMemory,
int64 cachedMemory)
{
fCommittedMemory = committedMemory;
fCachedMemory = cachedMemory;
@ -87,9 +87,9 @@ KernelMemoryBarMenuItem::DrawBar(bool force)
cadre.InsetBy(1, 1);
BRect r = cadre;
float grenze1 = cadre.left + (cadre.right - cadre.left)
double grenze1 = cadre.left + (cadre.right - cadre.left)
* fCachedMemory / fPhysicalMemory;
float grenze2 = cadre.left + (cadre.right - cadre.left)
double grenze2 = cadre.left + (cadre.right - cadre.left)
* fCommittedMemory / fPhysicalMemory;
if (grenze1 > cadre.right)
grenze1 = cadre.right;

View File

@ -1,20 +1,20 @@
/*
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
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _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);
void DrawBar(bool force);
void UpdateSituation(float committedMemory, float fCachedMemory);
void UpdateSituation(int64 committedMemory, int64 fCachedMemory);
private:
float fCachedMemory;
float fPhysicalMemory;
float fCommittedMemory;
int64 fCachedMemory;
int64 fPhysicalMemory;
int64 fCommittedMemory;
double fLastSum;
float fGrenze1;
float fGrenze2;
double fGrenze1;
double fGrenze2;
};
#endif // _KERNEL_MEMORY_BAR_MENU_ITEM_H_

View File

@ -135,8 +135,8 @@ MemoryBarMenuItem::DrawBar(bool force)
rect.InsetBy(1, 1);
BRect r = rect;
float grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory) / fCommitedMemory;
float grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory) / fCommitedMemory;
double grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory) / fCommitedMemory;
double grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory) / fCommitedMemory;
if (grenze1 > rect.right)
grenze1 = rect.right;
if (grenze2 > rect.right)
@ -234,7 +234,7 @@ MemoryBarMenuItem::GetContentSize(float* _width, float* _height)
int
MemoryBarMenuItem::UpdateSituation(int commitedMemory)
MemoryBarMenuItem::UpdateSituation(int64 commitedMemory)
{
fCommitedMemory = commitedMemory;
BarUpdate();
@ -247,8 +247,8 @@ MemoryBarMenuItem::BarUpdate()
{
area_info areaInfo;
int32 cookie = 0;
size_t lram_size = 0;
size_t lwram_size = 0;
int64 lram_size = 0;
int64 lwram_size = 0;
bool exists = false;
while (get_next_area_info(fTeamID, &cookie, &areaInfo) == B_OK) {

View File

@ -1,20 +1,20 @@
/*
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
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MEMORY_BAR_MENU_ITEM_H_
#define _MEMORY_BAR_MENU_ITEM_H_
@ -36,23 +36,23 @@ class MemoryBarMenuItem : public BMenuItem {
void DrawIcon();
void DrawBar(bool force);
int UpdateSituation(int commitedMemory);
int UpdateSituation(int64 commitedMemory);
void BarUpdate();
void Init();
void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
private:
int fPhysicalMemory;
int fCommitedMemory;
int fWriteMemory;
int fAllMemory;
int fLastCommited;
int fLastWrite;
int fLastAll;
int64 fPhysicalMemory;
int64 fCommitedMemory;
int64 fWriteMemory;
int64 fAllMemory;
int64 fLastCommited;
int64 fLastWrite;
int64 fLastAll;
team_id fTeamID;
BBitmap* fIcon;
float fGrenze1;
float fGrenze2;
double fGrenze1;
double fGrenze2;
bool fDeleteIcon;
};