Re: [eigen] Custom memory allocation for SparseMatrix?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen 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) {
    your_custom_free(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:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=166

Christoph



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

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: http://www.informatik.uni-bremen.de/robotik



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/