现在我知道了栈是相对于线程而言的。那么操作系统分配给不同应用程序(用户应用程序 vs 系统程序)的线程的栈空间默认都是1M吗?操作系统分配给C#应用程序线程的栈默认是1M,那么要修改这个值,具体怎么修改呢?
都是1M 可以修改 对于C# Thread 构造函数 (ThreadStart, Int32) 参数 start 类型:System.Threading.ThreadStart ThreadStart 委托,它表示此线程开始执行时要调用的方法。maxStackSize 类型:System.Int32 线程要使用的最大堆栈大小;如果为 0 则使用可执行文件的文件头中指定的默认最大堆栈大小。maxStackSize 可以自己指定这个值 实际上就是调用windows的api HANDLE WINAPI CreateThread( __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in SIZE_T dwStackSize, __in LPTHREAD_START_ROUTINE lpStartAddress, __in_opt LPVOID lpParameter, __in DWORD dwCreationFlags, __out_opt LPDWORD lpThreadId ); dwStackSize [in] The initial size of the stack, in bytes. The system rounds this value to the nearest page. If this parameter is zero, the new thread uses the default size for the executable. For more information, see Thread Stack Size. dwStackSize 可以自己指定 如果设置为0 则视为是默认1M
都是1M
可以修改
对于C#
Thread 构造函数 (ThreadStart, Int32)
参数
start
类型:System.Threading.ThreadStart
ThreadStart 委托,它表示此线程开始执行时要调用的方法。maxStackSize
类型:System.Int32
线程要使用的最大堆栈大小;如果为 0 则使用可执行文件的文件头中指定的默认最大堆栈大小。maxStackSize 可以自己指定这个值
实际上就是调用windows的api
HANDLE WINAPI CreateThread(
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in_opt LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out_opt LPDWORD lpThreadId
);
dwStackSize [in]
The initial size of the stack, in bytes. The system rounds this value to the nearest page. If this parameter is zero, the new thread uses the default size for the executable. For more information, see Thread Stack Size.
dwStackSize 可以自己指定 如果设置为0 则视为是默认1M
1. 你提到的“如果为 0 则使用可执行文件的文件头中指定的默认最大堆栈大小”,此处的可执行文件指的是什么,这个文件位置在哪?如何查看这个可执行文件指定的默认最大堆栈大小是多少呢?2. "实际上就是调用windows的api
HANDLE WINAPI CreateThread{...}"这个是怎么推出来的呀?给点详细的依据或思维过程吧。谢谢。
2、你可以找工具剖析下.net源码能说的就这些了