你如何更改默认的堆栈大小管理executable.net [英] How do you change default stack size for managed executable.net

查看:301
本文介绍了你如何更改默认的堆栈大小管理executable.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经发现,我们的自动生成的组件中的一个是,新的抛StackOverflowException()。这个类有(原谅请)被初始化(多数默认情况下(串)等)在构造400多个简单的属性。

We have discovered that one of our auto generated assemblies is throwing a StackOverflowException on new(). This class has (bear with me please) 400+ simple properties that are initialised (most by default(string) etc) in a constructor.

我们注意到,其罚款64位,但在32位它会爆炸!

We notice that its fine on 64 bits but on 32 bits it goes bang!

我们需要测试它是否合理为我所用的情况下创造了更大的缺省栈给我们喘息的余地,而我们重新设计了$ C​​ $ C发电机。

We need to test if it's reasonable for our use case to create a larger default stack to give us breathing room while we reengineer the code generator.

我们会ESP。有兴趣的话可能涉及到的app.config的解决方案。但我是一个现实主义者,所以,只要将是一件好事。

We would esp. interested in solutions that involve app.config if possible. But I'm a realist so anything would be good.

重新原因堆栈过流。我们已经缩小了有问题的构造函数中的错误。我的第一个IM pressions是无限递归的类型也。但是我们转载使用3行控制台应用程序中的错误是:

Re reasons for the the stack over flow. We've narrowed the error down the constructor in question. My first impressions were also of the type of infinite recursion. However we've reproduced the error using a 3 line console app that :

  • 在创建类的一个空实例。
  • 在呼吁谁的第一份工作是创建和空实例准备好通过的属性到类的非静态方法(克隆)。

它去一声巨响,因为它击中了第二个构造函数。

It goes bang as it hits the second constructor.

现在调试通过与我们看到的堆栈溢出是在Guid.NewGuid(在.NET源$ C ​​$ C),其传递的第二个参数的构造函数。的code的实际行是调用本机CoCreateGuid()调用。

now debugging through with the .net source code we see that the the stack overflow is in the Guid.NewGuid() which is passed as the second parameter to the constructor. The actual line of code is the call to the native CoCreateGuid() call.

因此,尽管它可以在CoCreateGuid一个bug(),我们要消除我们从问题code。我首先想到的是增加堆栈的大小大规模,看看这个错误再次出现。然后,因为我认为我们可以控制所有的用例,是替换对象初始化的构造 - 认为这可以减轻在堆栈上的pressure

铌。我们可以从发生,只需从类int属性去掉停止错误。

推荐答案

您可以<一href="http://www.atalasoft.com/cs/blogs/rickm/archive/2008/04/22/increasing-the-size-of-your-stack-net-memory-management-part-3.aspx"相对=nofollow>使用 EDITBIN 更改堆栈大小的可执行文件。你不能在app.config中做到这一点,据我所知。

You can use editbin to change the stack size for the executable. You can't do this in app.config as far as I'm aware.

另一种选择(也提到页)是创建一个新的线程与正确的堆栈大小。该网页提到了这种方法的优点和缺点。

Another option (also mentioned on that page) is to create a new thread with the "right" stack size. The page mentions the pros and cons of this approach.

我会感到惊讶,如果只设置在构造400的属性是问题的原因,但...这将是的一个的大栈帧 - 但除非你有若干的大筹码堆栈上的框架,我希望它会好起来的。另一种可能性是,你有无限递归的地方:)

I'd be surprised if just setting 400 properties in a constructor was the cause of the problem though... that's going to be one big stack frame - but unless you've got several big stack frames on the stack, I would expect it to be okay. The other possibility is that you've got endless recursion somewhere :)

编辑:另一种建议...

An alternative suggestion...

presumably你有很多的局部变量在此构造? (否则它不应该占用任何比其他任何调用更多的堆栈。)是否可以构造分成多个方法,设置(说)每个方法的20场?这将是棘手的,如果字段是只读的,无可否认的。

Presumably you have a lot of local variables in this constructor? (Otherwise it shouldn't take up any more stack than any other call.) Is it possible to split the constructor into multiple methods, setting (say) 20 fields per method? That will be tricky if the fields are read-only, admittedly.

如果你能给我们什么样的构造看起来像一个想法,那将有很大的帮助。您可能还需要使用ILDASM来看看它宣称的堆栈大小将是该构造函数。

If you could give us an idea of what the constructor looks like, that would help a lot. You might also want to use ildasm to see what it claims the stack size will be for that constructor.

只是为了检查,这​​个的的一类,而不是一个结构,对吧?

Just to check, this is a class rather than a struct, right?

这篇关于你如何更改默认的堆栈大小管理executable.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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