[ODE] alloc vs. malloc again

jon klein stjaerna at mac.com
Thu Jun 20 06:30:02 2002


I've seen that the issue of allocating memory on the stack has
come up a few times on this list, and that a lot of people have
had problems with crashes due to stack overflows.  While these
can generally be fixed by increasing the stack size, I think
there's a strong argument to be made for giving the option of
not using the stack for this temporary memory allocation.

The main issue is that for applications with an arbitrary number
of objects and contacts, it's impossible to come up with a stack
size at compile time which will be guaranteed to be big enough.

The specific problem that I'm having is that the OS X AppKit
threading code (NSThread) does not allow the stack size to be changed
for threads, meaning that I can't even fix the stack overflow in the
normal way.  This is clearly not ODE's fault, but the only fix for
me is to modify the LCP solver to use malloc/free.

Obviously allocating on the stack has a large speed advantage
over malloc/free, but for people who are more concerned about
stability and runtime scalability, I think that malloc/free
would do the trick.

Another solution, which would fix the speed issue, would be to
have static pointers to buffers which grow when necessary and
don't get freed at all until the program terminates.  This would
be even faster than allocating memory on the stack, but is
considerably more work.

Is there anybody else who would like to see either of these
options available (via a #define statement)?

Thanks,
- jon klein