Hi all,
Recently, I have encountered a problem and I tried to debug it. I found that system throw out a CMemoryException when I try to allocate 256MB memory.
I have a member function in one class . see the below list.
ClassA:ClassA()
{
...
mImage = NULL;
...
}
ClassA:~ClassA()
{
delete []mImage;
}
bool ClassA : FuncA()
{
{
catch( CMemoryException* pEX)
{
CString cstmp;
CString csOut;
MEMORYSTATUS stat;
GlobalMemoryStatus (&stat);
cstmp.Format("The MemoryStatus structure is %ld bytes long.\n",stat.dwLength);
csOut+=cstmp;
cstmp.Format("It should be %d.\n", sizeof (stat));
csOut+=cstmp;
cstmp.Format("%ld percent of memory is in use.\n",stat.dwMemoryLoad);
csOut+=cstmp;
cstmp.Format("There are %7d total Kbytes of physical memory.\n",stat.dwTotalPhys/ 1024);
csOut+=cstmp;
cstmp.Format("There are %7d free Kbytes of physical memory.\n",stat.dwAvailPhys/1024);
csOut+=cstmp;
cstmp.Format ("There are %7d total Kbytes of paging file.\n",stat.dwTotalPageFile/1024);
csOut+=cstmp;
cstmp.Format("There are %7d free Kbytes of paging file.\n",stat.dwAvailPageFile /1024);
csOut+=cstmp;
cstmp.Format("There are %7x total Kbytes of virtual memory.\n",stat.dwTotalVirtual/1024);
csOut+=cstmp;
cstmp.Format("There are %7x free Kbytes of virtual memory.\n",stat.dwAvailVirtual/1024);
csOut+=cstmp;
pEx->Delete();
AfxMessageBox(csOut);
}
}
When I called FuncA() to allocate memory and if I called another function beforre, system will throw out CMemoryException.
But if I called FuncA() to allocate memory and I don't called another function, sysem will not throw out CMemoryException.
When system throw out CMemoryException, I tried to print out the usage status of memory.
The result is as below
It should be 32.
36 percent of memory is in use.
There are 2096100 total Kbytes of physical memory.
There are 1321288 free Kbytes of physical memory.
There are 4041780 total Kbytes of paging file.
There are 3615048 free Kbytes of paging file.
There are 1fff80 total Kbytes of virtual memory.
There are 70e94 free Kbytes of virtual memory.