在.NET堆栈VS的Windows堆 [英] The .NET stack vs Windows stack

查看:215
本文介绍了在.NET堆栈VS的Windows堆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 Windows内部本书第5版在页面下面的评论360。

The Windows Internal book 5th edition has the following comment in page 360.


The stack size for the initial thread is taken from the image—there’s no way 
to specify another size.

据我所知,针对Windows操作系统,每个线程都有4K或16K(取决于​​系统)堆栈,并且大小是固定的。

I understand that for Windows OS, each thread is given 4K or 16K (depending on system) stack, and the size is fixed.

那么怎么样叠.NET?

Then how about the stack in .NET?

  • 在多大栈?
  • 堆栈的大小是固定的或可变的?
  • 是分配给每一个线程就像Windows的情况下?
  • 堆栈

推荐答案

是的,启动线程的大小是由.EXE文件头中的值确定。未必如此,因为Windows创建一个线程,的的任何code在程序可以运行。使用托管编译器写入该值。现在.NET编译器选择1 MB,当你的目标x86或任何CPU,4 MB,当你的目标64。但是,这是不固定的,你可以修改与Editbin.exe工具,/ STACK命令行选项的值。你可以在生成后事件运行此:

Yes, the size for the startup thread is determined by a value in the .EXE file header. Necessarily so because Windows creates that thread, before any code in the program can run. The managed compiler you use writes that value. Current .NET compilers select 1 MB when you target x86 or Any CPU, 4 MB when you target x64. This is however not fixed, you can modify the value with the Editbin.exe utility, /STACK command line option. You could run this in a post-build event:

  set path=%path%;$(DevEnvDir);$(DevEnvDir)..\..\vc\bin
  editbin.exe /STACK:2097152 "$(TargetPath)"

请注意,这不会在防爆preSS编辑工作。为您创建的线程的堆栈大小是你的控制之下,Thread类的构造函数有重载允许您指定的大小。你不能让它太小,剪辑的价值为256 KB。 4或16KB的方式太小,1 MB是默认的。

Note that this won't work in the Express edition. The stack size for threads that you create are under your control, the Thread class constructor has overloads that lets you specify the size. You cannot make it too small, it clips the value to 256 KB. 4 or 16KB is way too small, 1 MB is the default.

这篇关于在.NET堆栈VS的Windows堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆