Compartir a través de


Stack (Windows CE 5.0)

Send Feedback

The stack is the storage area for variables referenced in a function. Windows CE manages a separate stack for every thread in the system. The architecture of the stack depends on the microprocessor, but typically, the default stack limit is 64 KB, with 2 KB reserved for overflow error control. You can override the stack limit at compile time with the linker option /STACK.

Note   Exceeding the stack limit causes a system-access violation that shuts down your application. In addition, stack frames can be no larger than one page each or structured exception handling fails.

When the system creates a new thread, the kernel reserves memory for the stack. The amount of memory that the system reserves for the stack is determined by the /STACK parameter passed to the linker when the module is built. You can also change the stack size on a per-thread basis using the STACK_SIZE_PARAM_IS_A_RESERVATION flag.

When the system schedules a thread for the first time, the thread's stack memory is committed; it is committed one page at a time and committed only when needed. To prevent the initial commitment of stack memory from affecting performance, ensure that your thread is scheduled at least once before performing real-time processing. In the case of an IST, allocation of stack memory generally occurs because the thread performs several actions before settling down into a WaitForSingleObject loop. You can avoid allocating more stack memory, if your thread requires no more than the initial stack allocation. Because memory is typically limited in a Windows CE environment, at times the kernel will take back stack memory from threads that are no longer needed.

Reclaiming unused stack memory is controlled by the OEM and the parameters passed to the SetOOMEvent function. If the values passed to SetOOMEvent cause the system to search for stack memory, the kernel suspends each thread that has a free stack while memory from the stack is removed. To avoid this situation, carefully set the memory usage parameters for SetOOMEvent.

You can set an OAL variable that tells the kernel at what priority to recover stack space when memory is low.

Make the following declaration in your OAL:

extern DWORD dwNKMaxPrioNoScav;

The value of dwNKMaxPrioNoScav defines the highest priority for a thread that should not incur stack space recovery. Any thread with a priority lower than dwNKMaxPrioNoScav can have its stack space recovered by the kernel. The default setup by the kernel is 247, which is the value you see in dwNKMaxPrioNoScav. Use this variable in combination with the SetOOMEvent function to control when stack recovery is run. If stack recovery is run, dwNKMaxPrioNoScav, in combination with SetOOMEvent, determines which priority stack recovery should be applied.

See Also

Memory Architecture

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.