### Stack Probes

For the stack growth mechanism to work correctly, each 4K page must be accessed in the correct order. To ensure the correct access, IBM C and C++ Compilers generates one or more stack probes in the prolog of each procedure that has automatic storage greater than 2K. Stack probes start after 2K because exception handling may require up to an additional 2K of stack storage.

When a guard-page exception occurs, the stack probe instructions allow the exception mechanism to enlarge the stack if necessary. If an attempt is made to access the stack below the guard page, stack probes cause the operating system to allocate each page of the stack up to that access point and to create a new guard page.

Without stack probes, accessing the stack below the guard page is an access violation (you cannot access uncommitted pages). The process terminates. The compiler ensures that structures greater than 4K that are passed by value are placed on the stack to allow this mechanism to work.

Support for automatic stack growth is provided by default as needed.

Note: The _alloca function allocates storage on the stack. Unless you specify the /Gs+ compiler option, the compiler generates stack probes to allocate the required memory.

You do not need to use stack probes if:

- You have changed the linker default for the amount of committed memory and are sure that all local variables require less than this amount.
- Your program has only one thread. The stack is fully allocated for the first thread.
- You can guarantee that the stack will always be allocated. For example, you could write a guard routine to run once at the beginning of each thread and serially access each page up to the last page, leaving that page as a guard page.
- Your local variables require less than 2K of storage on the stack.

To turn off stack-probe generation, specify the /Gs+ compiler option. Because stack probes go into the prolog of every function with more than 2K of stack storage, your program will run faster with the stack probes turned off. However, it is only safe to turn off stack probes if you can meet one or more of the above criteria.

Stack Allocation

Set the Stack Size