Different memory footprint on RHEL 3.0 and 4.0
Hello,
I am running following program on RHEL 3 and RHEL 4 machines and seeing major difference in memory usage by the program. It takes roughly 830KB on RHEL 3 and between 3MB to 4MB on RHEL 4. Surprisingly RHEL 4 memory usage changes at every run.
My RHEL 3 machine is
Linux torlcc06 2.4.21-9.ELsmp #1 SMP Thu Jan 8 17:08:56 EST 2004 i686 i686 i386 GNU/Linux
and RHEL 4 machine is
Linux torlce06 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
I am using gcc-3.3.3 for compilation.
My test program code looks like:
#include <iostream>
#include <iomanip>
double getProcSize();
int main()
{
std::cout << std::setprecision(8);
std::cout << "proc size at start = " << getProcSize() << std::endl;
double* p = NULL;
for (int i = 0; i < 20; i++)
p = new double[1000];
std::cout << "proc size at end = " << getProcSize() << std::endl;
sleep(100);
}
double getProcSize()
{
double result = -1.0;
char buf[256];
FILE * file;
unsigned int pages;
snprintf(buf, sizeof(buf), "/proc/%d/statm", (unsigned int) getpid());
if ((file = fopen(buf, "r")) == NULL)
{
perror("open");
return 0;
}
fgets(buf, sizeof(buf), file);
fclose(file);
sscanf(buf, "%u", & pages);
return (pages * ::sysconf(_SC_PAGE_SIZE));
}
Can someone please explain me the possible reason(s) for this? and any suggetions to resolve this will really be appriciated.
Thanks in advance.
Prakash
|