[ODE] Stack overflow
Royce3
royce3 at ev1.net
Fri Jan 31 14:18:02 2003
Or like this:
class DAlloca
{
public:
void* alloca ( size_t bytes )
{
void *p = malloc ( bytes );
if ( p )
_mem.push_back ( p );
return p;
}
virtual ~DAlloca()
{
for ( int i = 0; i < _mem.size(); i++ )
free ( _mem[i] );
}
private:
std::vector<void*> _mem;
};
Allocate a single non-static DAlloca object at the
beginning of each function:
DAlloca dalloca;
replace all occurances of _alloca(n) with a call to:
dalloca.alloca(n);
--
Peace,
Royce3
>
>Subject: Re: [ODE] Stack overflow
> From: "Marco Grubert" <mgrubert@conitec.net>
> Date: Fri, 31 Jan 2003 12:31:52 -0800
> To: <ode@q12.org>
>
>> 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
>
>_______________________________________________
>ODE mailing list
>ODE@q12.org
>http://q12.org/mailman/listinfo/ode