Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-19 Thread Michael Ash
On Thu, Feb 19, 2009 at 1:29 PM, Leo Singer wrote: > I would rather not dynamically allocate that particular array because > the Cocoa application I am developing is simply a wrapper for a cross > platform C++ project. This particular project has to manage a number > of different resources, inclu

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-19 Thread Clark Cox
On Thu, Feb 19, 2009 at 10:29 AM, Leo Singer wrote: > A std::vector would be unsuitable also because in my actual > application (not the cooked example I sent out) I need to be able to > manipulate that memory directly. Not true; std::vector's memory is guaranteed to be contiguous; you can treat

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-19 Thread Ken Thomases
On Feb 19, 2009, at 12:29 PM, Leo Singer wrote: A std::vector would be unsuitable also because in my actual application (not the cooked example I sent out) I need to be able to manipulate that memory directly. std::vector guarantees that you're allowed to do that. Cheers, Ken ___

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-19 Thread Greg Parker
On Feb 19, 2009, at 10:29 AM, Leo Singer wrote: I would rather not dynamically allocate that particular array because the Cocoa application I am developing is simply a wrapper for a cross platform C++ project. This particular project has to manage a number of different resources, including an SQ

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-19 Thread Mike Abdullah
On 19 Feb 2009, at 18:29, Leo Singer wrote: Sorry, I meant to send this to the list. Leo -- Forwarded message -- From: Leo Singer Date: Thu, Feb 19, 2009 at 1:28 PM Subject: Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation To: Greg Parker

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-19 Thread Leo Singer
Sorry, I meant to send this to the list. Leo -- Forwarded message -- From: Leo Singer Date: Thu, Feb 19, 2009 at 1:28 PM Subject: Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation To: Greg Parker Thanks for all of the input on this. I

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Greg Parker
On Feb 18, 2009, at 3:22 AM, Michael Vannorsdel wrote: 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). A

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Clark S. Cox III
I would strongly reccommend using std::vector instead of a raw array. That way you're immune from stack size issues. Sent from my iPhone On Feb 18, 2009, at 0:31, Leo Singer wrote: Actually, if the big array and the loop are moved from the C++ method into the Objective C selector - (void) m

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Steve Christensen
Google is your friend. The first search result for "Mac OS X stack size" was , which says: "Each Mac OS X process is launched with a default stack size of 8 Megabytes. This allocation is used exclusively for the main thread's sta

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Michael Vannorsdel
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 t

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Mike Abdullah
Would this work? - (void)main { [[NSThread currentThread] setStackSize:stackSize]; // Do usual work } Actually, with a bit more reading, apparently not. You'd need to set the stack size before starting the thread, not after. In which case your only option is to subclass NSOp

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Leo Singer
OK, so there is a way to change the size of the stack for an NSThread. But how do I do this for an NSOperationQueue? NSThread has the following selector: - (void) setStackSize:(NSInteger)s; I need to find the equivalent selector for NSOperationQueue. Any ideas out there? Leo #import @interf

Re: Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Leo Singer
Actually, if the big array and the loop are moved from the C++ method into the Objective C selector - (void) main then the same EXEC_BAD_ACCESS occurs. So the problem is not related to C++. The following source code still exhibits the same problem: TestOperation.h //

Running out of memory on stack in C++ routine invoked within Cocoa NSOperation

2009-02-18 Thread Leo Singer
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