WinCE Memory Management Report
1. Windows CE to support dynamic allocation of virtual memory (virtual memory allocation), and a separate local heap space (Local and separate heaps), or even memory-mapped file (memory_mapped files, memory mapping simplifies file access. Instead of using a system-maintained pointer To write to the file, you can write directly to memory.)
2. The use of ROM and RAM in the Windows CE environment is different from our usual PC. RAM is divided into two areas: Proram Memory, also called System Heap, and Object Store.
l Object storage can be seen as a permanent virtual RAM disk. On the Pocket PC, when we turn off the display, the system does not actually power off, but enters a low-power sleep state (powered by the main battery). When we press the reset button, the Windows CE kernel finds the most recently created object storage in RAM. If you find it, use this object to store restart.
l RAM's another area is the program area. This area is like the RAM of the PC. It stores the space of the stack of the running program and the stack. The boundaries of object storage and program areas are movable. In the case of low memory, the system requests the user to provide partially available storage object spaces to run programs to meet the RAM needs of the program.
U PC, ROM is used to store BIOS, usually 64-128k. In the WindowCe system, the ROM is used to store the entire operating system and the OS binding application, and the size can be 4-32m. Therefore, the ROM under WinCE is like a small only hard drive.
u In WinCE OS, the ROM_BASED program can be accomplishing in place in place (Excute in place). That is, they do directly from the ROM instead of being loaded into the RAM and then execute. This can save not only valuable RAM resources, but also the program starts faster. The program in the ROM (in the object storage space or in the Flash memory) cannot be implemented.
3. Virtual memory. The OS uses micro-processed memory management units to translate virtual addresses to physical addresses.
u Page Memory. Under Wince OS, a page is 1K or 4K, depending on the microprocessor chip. Intel's ARM, one page is 4K.
The U virtual page has three states: unused (free), reserved, and occupied. A FREE page, as the name suggests can be assigned. A reserved page is already scheduled, so his virtual address space cannot be allocated to another thread of the operating system and this process. Its address is not mapped to physical space. A committed page is that it has been retained by a program and has been mapped directly to a physical address space.
4. WinCE address space
u For all applications, a single 2GB virtual address is implemented, but each application's memory space is protected to ensure that other applications cannot be accessed. From the lowest virtual address space, it is divided into 33 SLOT, each SLOT32M. Each SLOT is assigned to the current running process. The current activation of the Slot 0 is stored. When Wince is switched between processes, it retesses the address space and removes the old process, and the new process moves into slot 0. This task is to complete quickly by operating the microprocessor's page conversion table. u 33 Slot or more address area is reserved for OS and mapping memory mappings. Like Windows XP, WinCE has retained the lowest 64K address space, and any process cannot be accessed.
5. Query system memory.
u getsysteminfo (lpsystem_info)
U GlobalMemoryStatus (LPMEMORYSTATUS) (Paging Files Are Not Supported Under Windows CE)
6. Various memory allocation methods
u First, the Virtualxxxx function is used to reserve, submit, and release the virtual memory page. Then it is a heap API. Heaps use the application to manage the memory space area. There are two piles: the default local pile and independent stack. The heap API is static data that is defined by the compiler and is automatically assigned when loaded. Finally, it is stack, which stores local variables for each function in the application.
u WinCE does not support global stacks. So the global heap API, WinCe is not supported.
u The key to reducing memory usage in WINCE is to select the appropriate memory allocation policy.
6.1 Virtual Memory
It is the most basic in memory type. The system can call the virtual memory API to allocate space for other memory types, such as piles, stacks. VirtualLoc, VirtualFree, VirtualResize function A virtual memory page directly in this application's virtual memory space. You can use these functions to reserve, submit, and whether physical memory is available. (In the page-based, rounding the boundaries)
6.2 pile
Obviously, allocation of memory in pages is inefficient for most programs. And the heap can be applied and released in bytes. The particle size is smaller than the virtual memory function (at least 4 bytes). The system will automatically grow the size of the stack with the needs of the running program. When some of the blocks in the stack are released, the system checks if the entire page is released. If so, this page is defommit. This heap is likely to be split into some fragments, or this stack is almost empty, but the system still cannot release A Page from this heap unless it is empty.
u Local HEAP. Each application creates a default heap at startup. This stack can be operated using the Localalloc, LocalFree, and LocalRealloc functions.
u Separate Heaps. In order to avoid splitting the heap into a lot of fragments, if a continuous block space is needed for a while, a better way is to create a separate heap. When you actually apply for a space, you will be mapped or reserved or submit any memory when you create it. DESTROY This stack does not require the data blocks inside to be released.
6.3 stack
By default a stack space is 58K. When the stack space is gradually changed, the system will enter a low memory state. The maximum value of the stack space can be specified at the time of the link. Can be specified to 1M. note:
u Default stack space size is also the size of all other independent thread stacks.
u If there is no physical RAM available, the thread of the stack space will be suspended. If this memory needs cannot get a response within a given period of time, the system exception will pop up. In the case of low memory, you should not try to use a large number of stack spaces.
6.4 static data
The predefined memory block automatically assigns space when the program is loaded. The data in these blocks contains a static application string, buffer, and global variables, and a library of static links with this application. WinCE applies for two RAM blocks for an application: a use of read / write data, one for storing read-only data. Since these areas are allocated in a page, they are allocated, so that the static data segment is close to but cannot exceed the page range. If there is still a fairly space in the static data segment, some buffers that are dynamically applied can be moved to the static data area. Sometimes you can move some of the data in the read-only data area to the read and write data area according to the specific situation. The method of decision is to view the MAP file.
7. How WINCE handles the memory request for the application in low memory.
When the system runs more memory, the shell will automatically turn off the application without satisfaction. Therefore, WinCE provides some ways to assign valuable memory resources between all running programs.
u WM_Hibernate message. The OS first sends this message to the non-active program, requesting them to releasing multiple memory without destroying their inherent state, such as release GDI objects, buffer data, etc..
u Memory Thresholds. WinCE defines four memory status: NORMAL, LIMITED, LOW AND CRITICAL. The division of these states depends primarily on the currently available memory size. When the available memory is small, the system first sends a WM_Hibernate message, and then restricts the request for memory applications.