Re: Recursive functions and stack overload
Re: Recursive functions and stack overload
- Subject: Re: Recursive functions and stack overload
- From: Dado Colussi <email@hidden>
- Date: Wed, 26 Apr 2006 12:16:41 +0300
On Wed, 26 Apr 2006 10:26:27 +0200
Paolo Bertani <email@hidden> wrote:
Hi,
I'm sorting a plain C array with the "Quicksort" algorithm.
The quicksort() function calls itself recursively for a numer of times
that depends on the size of the array and the array's initial
configuration.
Since the array contains 10,000-100,000 elements the function calls
itself many times.
Is there the risk of some sort of stack overload?
This is not really a Cocoa related question.
It depends. In a single-threaded application where stack can grow quite
freely you're unlikely to get into troubles. However, my one-cent-advice for
multi-threading is to avoid using stack when possible. At some point you
might want to minimize the memory allocated for thread stacks and then you
perhaps would want have a non-recursive sorting algorithm with smaller (and
possibly input-independent) stack requirement. At worst you hit the OS
default thread stack limit (512k for NSThreads) and experience some very
weird effects, which can be hard to trace down to stack overflowing.
See http://developer.apple.com/qa/qa2005/qa1419.html for stack tuning on Mac
OS X.
Dado
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden