Really it would be best to malloc the space, use it, and free it. Once you get to huge stack usage you gamble that you won't run out when there can be other higher up calls also consuming some (frameworks, libs, 3rd party code, ect). Also if you only use the large amount once in a while then you have a bunch of unutilized memory sitting around.

In your test NSOperation's setup calls probably use just enough stack space to make your block run short. It also doesn't help secondary threads usually have smaller stack sizes.

void TestOperationImpl::go()
{
   int * bigArray = malloc(sizeof(int) * 256000);

   for (int j = 0 ; j < 256000 && !cancelled ; j ++)
   {
       bigArray[j] = 2*j;
   }

  free(bigArray);
}



On Feb 18, 2009, at 1:16 AM, Leo Singer wrote:

I have a C++ method that I am invoking from within the - (void) main
selector of an NSOperation.  My Cocoa application is crashing because
this particular C++ method puts a huge amount of data on the stack.  I
am getting an EXEC_BAD_ACCESS error.  However, the same C++ routine
works fine if I call it from within a command line C++ program.

I have contrived some sample code to illustrate the problem.
TestOperation is an (Objective C) subclass of NSOperation; I am
running the NSOperation in a separate thread by putting it into an
NSOperationQueue.  TestOperationImpl is a C++ class.  The NSOperation
is responsible for doing one thing only: calling the go() method on an
instance of TestOperationImpl.

Note the very large array of ints that is declared inside
TestOperationImpl::go().  If it is changed to an array of shorts or an
array of chars, then this example code works fine, no EXEC_BAD_ACCESS.

Is there any way for me to give my application more memory, or at
least give more memory to the thread that is running this C++ method?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to