What's the memory overhead for a single windows threads?

后端 未结 4 918
礼貌的吻别
礼貌的吻别 2020-12-18 04:40

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++) and CLR threads as view via Task Man

相关标签:
4条回答
  • 2020-12-18 05:18

    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.

    0 讨论(0)
  • 2020-12-18 05:19

    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.

    0 讨论(0)
  • 2020-12-18 05:19

    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.

    0 讨论(0)
  • 2020-12-18 05:36

    The default is 1 MB for both native and CLR threads. You can alter it, though that's usually a bad idea.

    0 讨论(0)
提交回复
热议问题