Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

The stack is the storage area for variables referenced in a function. Windows Mobile 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 8 KB, or two pages, 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. The stack size can be set for newly created threads with the CreateThreadfunction by setting cbStackto the appropriate size and fdwCreate to STACK_SIZE_PARAM_IS_A_RESERVATION.

When the system schedules a thread for the first time, the thread's stack memory is committed one page at a time 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 interrup service thread (IST), allocation of stack memory generally occurs because the thread performs several actions before settling down into a WaitForSingleObjectloop. 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 Mobile environment, at times the kernel takes back stack memory from threads that are no longer needed.

See Also