Question

In Stephen Cleary's article in MSDN magazine "Introduction to Async/Await on ASP.NET" he says that "every thread pool thread on a modern OS has a 1MB stack." (modern OS == Windows 7/8 for this discussion) But I thought that this was 1MB of virtual memory, and that physical memory was allocated dynamically as the stack grew. Based on my dated C++ threading knowledge on other OSs, I believe that actual stack sizes rarely exceed 64k, especially in languages that make heavy use of the heap like .NET.

Does Windows allocate 1MB of physical memory, or does the stack dynamically allocate more memory as needed? Maybe it is cheaper to allocate it all up front now and rely on swapping it out as needed? I was going to test this using the profiler but I don't see how to get the stack size from it.

Was it helpful?

Solution

The link Robert Harvey added as a comment does explain this more explicitly, but, by default, Windows allocates 1MB of virtual memory which is committed as physical memory as needed (as you described).

Licensed under: CC-BY-SA with attribution
scroll top