I developed a private allocator greatly reducing the number of malloc's/free's if Eigen is used in a (longer) loop doing the same calculation over and over. To test the code, please pull from my fork at https://bitbucket.org/MarkusS/eigen-private-alloc. The only Eigen file modified is Memory.h. I added two files PrivateAlloc.h and Mutex.h (both in the same directory src/Core/util) to implement the private allocator
To use the private allocator, just defined EIGEN_USE_PRIVATE_ALLOC before any eigen include.
You can tune the behavior by adjusting some defines at the beginning the PrivateAlloc.h (like bucket and list sizes).
The code is tested with Mac OSX (10.6.6) and Linux (Ubuntu 10.4 x86).
thank you for the patch, we are currently focusing on releasing 3.0-beta3 and more generally 3.0, so we'll look at this feature later...
This has been postponed several times. Is there still actual interest in this?
It might actually help to circumvent other problems, like bug 789.
Generally, instead of making this a Yes/No switch between two predefined allocators, I'd rather suggest defining EIGEN_USE_CUSTOM_ALLOC to the name of the allocator which is to be used, and if that is not defined use Eigen::aligned_allocator. Related is bug 779.
One can still globally bypass malloc but a finer control would be welcome.
A related idea would be to use a stack-based allocator for the temporaries created by Eigen itself which requires to somehow change the allocator at runtime, for instance via a template parameter (a la STL), or ctor argument, or...