辅助线程的栈大小,DEBUG 和 RELEASE 版本的显着差异 [英] Stack size of secondary threads, significant differences between DEBUG and RELEASE versions

查看:62
本文介绍了辅助线程的栈大小,DEBUG 和 RELEASE 版本的显着差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 iPhone 应用程序(XCode 3.2.4,iOS3.1.3)中,如果我在 RELEASE 模式下运行应用程序,一切都很好,但在调试模式下,应用程序崩溃并出现 EXC_BAD_ACCESS 异常.该应用程序进行一些复杂的计算.所有主要代码都包含在几个 C++ 静态库中,UIApplication 仅从这些库中的一个创建一个对象并调用该对象的方法.

In my iPhone application (XCode 3.2.4, iOS3.1.3), if I run the application in RELEASE mode, all is fine, but in DEBUG mode, the application crashes with an EXC_BAD_ACCESS exception. The application does some complex calculations. All the main code is contained in several C++ static libraries and the UIApplication only creates an object from one of these libraries and calls a method of this object.

如果我将调用复杂计算的代码放入辅助线程,我仍然有相同的行为:DEBUG 模式下的 EXC_BAD_ACCESS 异常,而 RELEASE 模式下没有问题.

If I put into a secondary thread the code which calls the complex calculations, I still have the same behavior: EXC_BAD_ACCESS exception in DEBUG mode and no problem in RELEASE mode.

然后我查看了线程堆栈大小.默认情况下,iOS 将线程堆栈大小设置为辅助线程为 512 KB,主线程为 1024 KB.我查看了线程堆栈大小所需的最小值以正确运行我的应用程序.我发现了以下结果:RELEASE 版本为 40 KB.DEBUG 版本为 1168 KB.

Then I've looked around the thread stack size. By default, iOS set a thread stack size with 512 Kbytes for secondary threads and 1024 Kbytes for the main thread. I've looked the minimal required value for the thread stack size to run correctly my application. I've found the following result: 40 Kbytes for the RELEASE version. 1168 Kbytes for the DEBUG version.

DEBUG 版本中的值 1168 KB 解释了为什么在主线程中,应用程序会崩溃(主线程的默认堆栈大小为 1024 KB).

The value 1168 Kbytes in DEBUG version explains why in the main thread, the application will crash (defaut stack size for the main thread is 1024 Kbytes).

我真的不明白为什么我的应用程序的 RELEASE 和 DEBUG 版本所需的线程堆栈大小如此不同(40 KB 与 1168 Kb !!!).我需要任何帮助来理解这个问题.

I really don't understand why the required thread stack size is so different between the RELEASE and DEBUG version of my application (40 KB vs 1168 Kb !!!). I would like any help to understand this issue.

谢谢.马克

推荐答案

代码和库的调试版本包含额外的自测、额外的局部变量和验证并不罕见.也许这些会增加您对代码的需求.

It is not unusual for debug versions of code and libraries to contain extra self-tests, extra local variables and verification. Perhaps these are increasing the needs of your code.

特别是,将一些缓冲区定义为局部变量并占用大量堆栈是相对容易的.您可能会在一个或多个占用堆栈的地方发现类似的东西:

In particular, it is relatively easy to define some buffer as a local variable and take large amounts of stack. You might find something like this in one or more places taking up stack:

#ifdef _DEBUG
   testBuffer[bufferSize]; 
#endif

如果将 'bufferSize' 定义为 10K,则将使用整个 40K 堆栈的 1/4.

If 'bufferSize' was defined as 10K, that would use up 1/4 of your entire 40K stack.

或者一个仅用于调试的函数使用大量堆栈.

Or perhaps a debug-only function uses a large amount of stack.

也可能是您的调试版本的设置使用了任意数量的 Apple 测试设置.MallocStack、GuardMalloc、NSZombiesEnabled 之类的东西需要更多内存.

It may also be that the settings of your debug build are using any number of Apple's test settings. Things like MallocStack, GuardMalloc, NSZombiesEnabled will require more memory.

这篇关于辅助线程的栈大小,DEBUG 和 RELEASE 版本的显着差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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