Re: [eigen] patch to throw std::bad_alloc

[ Thread Index | Date Index | More Archives ]


Thanks a lot for your patch. Having never worked with assertions I
actually didn't know how this should be done.

I committed your patch with some modifications, so if you svn up you
could try it and see if you like it.

Notice that on the linux platform, Eigen will also try to use dynamic
stack allocation in ei_stack_alloc() in Memory.h, which has undefined
behavior in case of stack overflow. Which I guess you would frown upon
;) so if you want to disable that, just define

If you define EIGEN_STACK_ALLOCATION_LIMIT to 0 and have exceptions
enabled it's guaranteed that any kind of bad allocation will throw a

Now the comments...

>+#include <new>

I moved that to the Eigen/Core header. The place were you put it is
actually included inside namespace Eigen!
Also we only include that if exceptions are enabled. I introduced

> inline T* ei_aligned_malloc(size_t size)
> {

Here I made some modifications: fix the warning "unused variable
failed" when exceptions are disabled, avoid an if(), etc.

>+      throw std::bad_alloc;

This failed to compile, I had to add parentheses. OK? (i don't have
any experience)

Thanks again,

2008/12/16 Kenneth Riddile <kfriddile@xxxxxxxxx>:
> After discussion in IRC, I have written and attached a patch to Memory.h to
> throw std::bad_alloc when ei_aligned_malloc() fails to allocate memory.  If
> exceptions are disabled, ei_aligned_malloc() should behave exactly as it did
> before.  I haven't actually been able to compile this code due to problems
> with my machine here at work, so I would appreciate someone testing it for
> me.  Also, if there are any unit tests that test the behavior of
> ei_aligned_malloc(), they may need to be altered since its behavior is now
> different if compiled with exceptions on.  I don't know how Eigen structures
> its unit tests, but I know most test suites I've used have some way to
> verify that a particular exception was or was not thrown.
> -Kenny Riddile


Mail converted by MHonArc 2.6.19+