[ODE] Stack overflow

Marco Grubert mgrubert at conitec.net
Fri Jan 31 13:33:01 2003


>  The question I ask myself (and you guys) : does
> anybody knows how to define an implicit memory
> de-allocation when a function ends ( because if such a
> thing isn't found we might be looking at some major
> re-write of the function using alloca) ?

How about something like this (at least for C++)

struct CMem() {
  CMem()  { CMemMarker::pCurrentStack=new char[A_FEW_MEGS]; }
  ~CMem() { delete[] CMemMarker::pCurrentStack; }
  static void* pCurrentStack;
};

and then just add a var to each critical function (stepIsland, solveLCP,
etc.) :

void myFunc() {
  CMem mem;

  // do stuff..
}

Then alloca would just needs to be rewritten to fetch memory from the region
allocated above. A better way would be to have the user supply a pointer to
that memory so that only an internal counter gets reset while the memory
region persists for several calls to dWorldStep.

- Marco Grubert