Tuesday, 12 May 2009

Living in the box ....

or developing applications with only 32MB virtual memory on Windows CE systems (before WinCE 6.0).
There are several sources about Windows CE Memory Management, my favorites are:
- Advanced Memory Management by Douglas Boling
- Virtual Memory Layout: Windows CE 5.0 vs. Windows Embedded CE 6.0 on MSDN
- What is virtual memory? by Sue Loh

but how to detect, if your app is running out of "in proc" 32MB virtual memory?
Very usefull is a tool provided with the Platform Builder on the Windows CE Shell called "mi" (memory information).
You can input mi [kernel | full] to display memory information. The full parameter displays a set of tables showing the virtual memory usage for all the processes in the system.
You will receive a detailed info about virtual memory usage in the following form:

Memory usage for Process 819b5de8: 'device.exe' pid 3
Slot base 08000000 Section ptr 83fca000
08000000(1): -----r----------
08010000(0): -CCCCCCCCCCCc
08020000(0): ------------S--S
08050000(0): WWWWWW---------
08060000(0): ---------------S
08070000(0): ---------------S
08080000(0): ---------------S
08090000(0): ---------------S
In the memory information "--" represents the memory space is reserved but not in use. Which indicates that a virtual page is currently allocated but not mapped to any physical memory. "C" represents code pages in ROM, "S" indicates a virtual page that holds a stack, "W" indicates a virtual page that holds read-write data and "R" represents r/o data pages in ROM.
Detailed info about the "mi full" output is provided in the Platform Builde help.

The investigation of the commandline output may be hard, but you can get these information also as an image, which is easier to interpret as the commandline output.
Just take a look at the "VirtualMemory.exe" from CodeProject.

Red means, that memory block is completely empty. Blue means that the memory space has been reserved. Green means the memory space has been committed. A mixture of colors means some combination of all three.
This app allows you a very quick and detailed analysis of the usage of the virtual memory on your Windows CE system.

Then avoid memory leaks and have fun!

No comments: