What happens if I give contradictory values for the stack commit and stack reserve?

Raymond Chen

Raymond

The Create­Thread function lets you specify a custom stack commit or a custom maximum stack size. The Create­Fiber function lets you specify a custom stack commit, and the Create­Fiber­Ex function lets you specify both.

Function + flagCan customize?
Initial commitMaximum size
Create­Thread 
Create­Thread +
STACK_SIZE_PARAM_IS_
A_RESERVATION
 
Create­Fiber 
Create­Fiber­Ex

In all cases, if you choose not to specify a custom value (typically by passing zero), then you get the default value specified by the executable file header.

But what if the results end up contradictory because you passed a commit greater than the maximum size?

The value might be contradictory because you called Create­Fiber­Ex and passed explicit values that specify an initial commit greater than the stack maximum size. But more likely is that the value ends up contradictory by accident because you specified one of the values and let the executable file header choose the other.

In the case where the calculated commit is greater than the calculated maximum size, the system silently increases the stack maximum size to be at least as large as the commit. The amount of this adjustment is not contractual, but in practice it rounds the stack maximum size to the next higher megabyte.

Even if the values you pass are not contradictory, there are still adjustments necessary. Since commit is measured in pages, the initial commit is rounded upward to the next page boundary. And since the address space is allocated in chunks of 64KB, the stack maximum size is rounded upward to the next multiple of 64KB.

There are some other adjustments that occur in unusual conditions, and the precise details of those adjustments have varied over time. But the thing to keep in mind that contradictory values for the stack initial commit and maximum size are not considered errors. The system will simply try its best to give you a stack that is “inspired by” your requested commit and reserve sizes.

0 comments

Comments are closed. Login to edit/delete your existing comments