B
Beorne
I'm using WindowsCE 5.0 with CF 2.0
I'm trying to detect the available memory so to detect when the memory
usage is low.
After a good search time I've found that the good indicator of
available memory is tha dwAvailVirtual field of the memoryStatus
structure, that considers the process memory and not the whole memory.
I've built a test application that at every cycle allocates an array
32K more than the previous (in practice it allocates the allocable
minimum, 64K).
for (int i = 1; i < 100000; i ++)
{
GC.Collect(); // probably useless
byte[] array = new byte[1024 * i * 32];
// probably useless
for (int j = 0; j < array.Length; j++)
array[j] = (byte)0;
Util.GlobalMemoryStatusCE(ref ms); //wrapper for
GlobalMemoryStatus
str =
"GC.GetTotalMemory = " + (int)(GC.GetTotalMemory
(false) / 1024) + "\n" +
"ms.MemoryLoad = " + ms.dwMemoryLoad + "\n" +
"ms.TotalPhys = " + (int)(ms.dwTotalPhys / 1024) +
"\n" +
"ms.AvailPhys = " + (int)(ms.dwAvailPhys / 1024) +
"\n" +
"ms.dwTotalVirtual = " + (int)(ms.dwTotalVirtual /
1024) + "\n" +
"ms.dwAvailVirtual = " + (int)(ms.dwAvailVirtual /
1024) + "\n";
Console.WriteLine(i + "\n" + str.ToString());
}
The problem is that the application goes in out of memory when there
are 9 Mb of allocable memory left ...
Last printing:
303
GC.GetTotalMemory = 9699
ms.MemoryLoad = 48
ms.TotalPhys = 78552
ms.AvailPhys = 41356
ms.dwTotalVirtual = 32768
ms.dwAvailVirtual = 9792 <----
Why?
Thanks.
I'm trying to detect the available memory so to detect when the memory
usage is low.
After a good search time I've found that the good indicator of
available memory is tha dwAvailVirtual field of the memoryStatus
structure, that considers the process memory and not the whole memory.
I've built a test application that at every cycle allocates an array
32K more than the previous (in practice it allocates the allocable
minimum, 64K).
for (int i = 1; i < 100000; i ++)
{
GC.Collect(); // probably useless
byte[] array = new byte[1024 * i * 32];
// probably useless
for (int j = 0; j < array.Length; j++)
array[j] = (byte)0;
Util.GlobalMemoryStatusCE(ref ms); //wrapper for
GlobalMemoryStatus
str =
"GC.GetTotalMemory = " + (int)(GC.GetTotalMemory
(false) / 1024) + "\n" +
"ms.MemoryLoad = " + ms.dwMemoryLoad + "\n" +
"ms.TotalPhys = " + (int)(ms.dwTotalPhys / 1024) +
"\n" +
"ms.AvailPhys = " + (int)(ms.dwAvailPhys / 1024) +
"\n" +
"ms.dwTotalVirtual = " + (int)(ms.dwTotalVirtual /
1024) + "\n" +
"ms.dwAvailVirtual = " + (int)(ms.dwAvailVirtual /
1024) + "\n";
Console.WriteLine(i + "\n" + str.ToString());
}
The problem is that the application goes in out of memory when there
are 9 Mb of allocable memory left ...
Last printing:
303
GC.GetTotalMemory = 9699
ms.MemoryLoad = 48
ms.TotalPhys = 78552
ms.AvailPhys = 41356
ms.dwTotalVirtual = 32768
ms.dwAvailVirtual = 9792 <----
Why?
Thanks.