Hi, 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? Thanks, Leo //////////////// TestOperation.h ///////////////////// #import <Cocoa/Cocoa.h> class TestOperationImpl { private: bool cancelled; public: TestOperationImpl(); void go(); void cancel(); }; @interface TestOperation : NSOperation { TestOperationImpl* testOpImpl; } - initWithController: (TestOperationController*) controller; @end //////////////// End of TestOperation.h ///////////////////// //////////////// TestOperation.mm ///////////////////// #import "TestOperation.h" TestOperationImpl::TestOperationImpl(TestOperationController* controller) : cancelled(false) { } void TestOperationImpl::go() { int bigArray[256000]; for (int j = 0 ; j < 256000 && !cancelled ; j ++) { bigArray[j] = 2*j; } } void TestOperationImpl::cancel() { cancelled = true; } @implementation TestOperation - initWithController: (TestOperationController*) ctrl { if (self = [self init]) testOpImpl = new TestOperationImpl(ctrl); controller = ctrl; return self; } - (void) dealloc { delete testOpImpl; [super dealloc]; } - (void) cancel { testOpImpl->cancel(); [super cancel]; } - (void) main { testOpImpl->go(); } @end //////////////// End of TestOperation.mm ///////////////////// _______________________________________________ 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