http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453(v=vs.85).aspx The number of threads a process can create is limited by the available virtual memory. By default, every thread has one megabyte of stack space. Therefore, you can create at most 2,048 threads. If you reduce the default stack size, you can create more threads. However, your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue.
这样开线程占用的内存不属于working set,你可以打印当前进程的 VirtualMemorySize64 属性看这个内存增长,会看到这样子确实差不多到了2G的时候out of memory想看更详细的内存占用,可以使用sysinternals的工具VMMap,可以看到大量内存被Stack项占用,也就是分配给线程的栈。
但一部分地址是系统占用了,
你的程序本身再用去一部分,
其他相关DLL(例如NET平台)又去一部分,最后可供你使用的,大约就是1.5G
你可以执行如下简单代码测试:
int[,] i=new int[20000,20000];
The number of threads a process can create is limited by the available virtual memory. By default, every thread has one megabyte of stack space. Therefore, you can create at most 2,048 threads. If you reduce the default stack size, you can create more threads. However, your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue.
这用c++很容易实现,不断new数组就行了。然后就会看到,任务管理器中的debug程序进程占用的内存迅速上升,直到2G多
http://blogs.technet.com/b/russinovich/archive/2009/07/08/3261309.aspx