Re: [eigen] Custom memory allocation for SparseMatrix?

[ Thread Index | Date Index | More Archives ]

C++ allows to globally overwrite new/delete like this:

  void* operator new (size_t size) {
    void *p=your_custom_malloc(size);
    // throw if malloc failed:
    if (p==0)  throw std::bad_alloc();
    return p;
  void operator delete (void *p) {

But that would affect every new/delete.

If you don't want that, I guess there is no easy solution at the moment without changing the CompressedStorage class. An overly complicated alternative would be to work on custom-allocated Map<SparseMatrix>.

Would you like to change all SparseMatrix, or do you need to decide for each matrix where it shall be allocated (i.e., via a template parameter, such as in the std-containers)?

Furthermore, do you want the same for dynamic dense matrices? Then this BZ entry is related:


On 2016-04-15 13:22, Ola Røer Thorsen wrote:

I'm using Eigen 3.2 on a STM32F7 arm mcu. Quite successfully so far!

The memory on this device is separated into two parts, where there is some
Tightly-Coupled Memory (64k) that we use for the stack and statically
initialized variables. This memory is significantly faster to use compared
with the normal memory.

I want to use a sparse matrix for a calculation. As far as I can see
SparseMatrix uses regular memory allocation from the heap (new/delete). In
my case, this uses the regular "slow" memory. It runs ok, but I know there
is much gain in using the DTCM memory.

Is there some trivial way to make SparseMatrix use a custom allocator? I
guess one alternative is to modify my version of Eigen so that the
CompressedStorage class does something else than normal, but it would be
nice not having to modify Eigen itself.

Best regards,
Ola Røer Thorsen

 Dipl. Inf., Dipl. Math. Christoph Hertzberg

 Universität Bremen
 FB 3 - Mathematik und Informatik
 AG Robotik
 Robert-Hooke-Straße 1
 28359 Bremen, Germany

 Zentrale: +49 421 178 45-6611

 Besuchsadresse der Nebengeschäftsstelle:
 Robert-Hooke-Straße 5
 28359 Bremen, Germany

 Tel.:    +49 421 178 45-4021
 Empfang: +49 421 178 45-6600
 Fax:     +49 421 178 45-4150
 E-Mail:  chtz@xxxxxxxxxxxxxxxxxxxxxxxx

 Weitere Informationen:

Mail converted by MHonArc 2.6.19+