You do not delete material allocated on the stack; it is automatically corrected, because when you exit the current area, the stack pointer returns to the previous frame of stack 1, so all the memory used for objects in the current area is effectively restored.
In principle, the entire stack is allocated when the application is loaded into memory, so it has a fixed-size structure that is reused repeatedly (while the code stream moves to and from areas); The OS can play smart tricks (using protective pages to fix the top of the stack, which were just reserved at the beginning of the application), but in general this should not bother you.
The stack size is part of the PE header (executable file header), and you can set it using the linker. You can get this value for the loaded executable by tracking in PE structures loaded into memory (basically its HMODULE is where the executable is displayed in memory); I think the ImageHelper library might be useful in this task.
- Naturally, after the launch of destructors; By the way, FPO can make a difference here, but the concept remains the same.
Edit
In other words, if I manually access memory up to 1 MB, can windows cause access violation?
If it has already been committed (i.e. you allocated and freed 1 MB of objects on the stack), I do not think that this could happen.
Windows will not have a clue that this part of the stack is no longer in use. Windows can determine if it needs to make more pages using security pages to detect access to the top of the stack, but it may not know that these pages are no longer in use.
In fact, he could look for a stack pointer when switching contexts, but he could break applications that would be βsmartβ things with a stack, and overall it would be an optimization that is not worth the effort: if there is no memory, these pages can still be unloaded.
However, in order to play it safely (for example, if you donβt know if this distribution has occurred), you must read the stack going up from the current used section, so if the pages up have not been committed yet, you still touch guard pages, warning Windows to have more pages for the stack.