Processes

Windows CE can run up to 32 processes at one time. Each process starts with a single thread—often called the "primary thread"—which provides the resources that are required to run an application. Windows CE creates a primary thread when the loader calls the WinMain function. A process can also create additional threads when needed. The number of additional threads a process can create is limited only by the amount of random access memory (RAM) available on the device.

When the Windows CE OS initializes, it creates a single 4-gigabyte (GB) virtual address space. The address space is divided into 33 "slots," and each slot is 32 megabytes (MBs). The address space is shared by all processes. When a process initializes, Windows CE selects an open slot for the process in the system's address space. Slot zero is reserved for the currently running process.

In addition to assigning a slot for each process, Windows CE creates a stack for the thread and a heap for the process. Each stack has an initial size of at least 1 kilobyte (KB), which is committed on demand. The amount of stack space that is reserved by the system is specified in the (/STACK) option for the linker. Because the stack size is CPU-dependent, on some devices the system allocates 4 KB for each stack . The maximum number of threads is dependent upon the amount of available memory. You can allocate additional memory, outside of the 32 MB that is assigned to each slot, by using memory-mapped files or by calling the VirtualAlloc function.

The following illustration shows how memory is allocated in the Windows CE address space.

When a process initializes, the OS stores in the slot that is assigned to the process all of the dynamic-link libraries (DLLs), the stack, the heap, the application code, and the data section for each process. DLLs are loaded at the top of the slot, followed by the stack, the heap, and the executable file (.exe). The bottom 64 KB is always left free. DLLs are controlled by the loader, which loads all DLLs at the same address for each process.