5

I use to work with microcontrollers. The RTOSs that I employ in my applications do not have free and malloc (and other calls like assert), sometimes they could be available, but I prefer to have everything Static in my system.

I have started to employ linear Algebra, but most of them need dynamic memory. My matrices are dense and 'small' (not more than 10x10).

I really like Eigen (everything can be static decided in compile time), but apparently there is a bug calling for asserts which are not provided by my RTOS (even with -DNDEBUG). The library should provide matrix decomposition routines (like QR, Cholesky, LU...)

I would prefer C instead C++. Any suggestions? Many thanks in advance!

3
  • Which microcontroller architecture/family are you using, with what compiler? GCC?
    – Bojangles
    Jun 10, 2012 at 10:08
  • Why not just add your own assert macro/header? assert is just a macro, and you can define it to nothing to make it compile. But then to actually make use of asserts, you'd define it to something like if (!(expr)) { stop_program_however_that_is(); } unless NDEBUG is defined. Jun 10, 2012 at 10:10
  • Thanks for the quick responses. The architectures are CortexM3/4/4F (or even ARM7TDMI). I am employing GCC. I will also test redefining the macro assert.
    – user1145038
    Jun 10, 2012 at 10:27

3 Answers 3

4

Anything wrong with CLAPACK? Or even straight Fortran LAPACK (you can compile it with gfortran, which is part of gcc).

[C]LAPACK's routines take all memory buffers in their arguments as already allocated, and do not do themselves any heap allocation whatsoever. For the routines that take "work" buffers in addition to the other arguments (for example, dgesdd for computing an SVD), you can usually call them with special "size only" argument, and get back in response the required size for the work buffers, which you can then allocate however you wish.

1
  • this was/is the beauty of FORTRAN conventions; to avoid RAM allocation errors in libraries, users had to allocate() all their own RAM, and pass it in. Ahh, the days of work arrays...
    – tehwalrus
    Dec 4, 2012 at 9:35
1

Redefining the assert macro seems a good solution.

But you can even provide your own malloc and free implementation or statically linking with the appropriate memory management library: http://blog.reverberate.org/2009/02/one-malloc-to-rule-them-all.html

0

If Q16.16 fixed point math is fine for your application, libfixmatrix can be an option:

https://github.com/PetteriAimonen/libfixmatrix