Is it 1 Mb of stack per thread? Or is that just CLR threads?
I want to know the memory over head of native windows threads (c++) an开发者_运维问答d CLR threads as view via Task Manager.
Thanks
The default is 1 MB for both native and CLR threads. You can alter it, though that's usually a bad idea.
See the Mark Russinovich blog about win32 kernel limits for a description how big a single thread is, and how much overhead is used.
How much resources the .NET thread uses can be difficult to predict. I would guess, not much more.
The memory overhead (in RAM) will be one memory page. So (depending on your platform) this will likely be 4KB.
The default stack size for both is 1MB. However that is virtual memory only, so thats no RAM overhead unless it is used.
As per the previous answers the basic overhead is 1MB per thread. I won't go into the various nuances - the other answers have them covered.
For Microsoft Visual C/C++ threads you also have the per-thread overhead of any C runtime workspace that is allocated on demand (and stored using Thread Local Storage TlsAlloc()) to perform work such as sprintf(), scanf(), strtol() etc. I don't have any exact figures - you would need to scan the source to the Microsoft CRT to calculate that.
For other C/C++ runtimes (gcc/g++/borland/digital mars) there may or may not be similar per-thread data held, its an implementation detail.
None of us know the internals of the .Net Execution Engine, but there is probably some per-thread data stored there as well. Going to be hard to figure out what that overhead is though.
精彩评论