# Configurable size LUT using array in C - embedded systems

I am working with the STM32F7 MCU in a project where I need to compute and create a LUT with the values of a signal which I will finally send to the DAC.

The problem with the LUT is that the size will be known only at run-time because it depends on some parameters sent to the MCU from a PC. I was searching info about how to implement that in C and the answer seems to be always the same: malloc().

I also read that malloc() is not a good way to allocate memory when working with embedded systems so I am wondering whether is there any way to implement such functionality in C not using malloc() (initialize an array using a variable calculated at run-time).

• malloc is for allocating large blocks of memory, malloc has been hand optimized for decades and your probably not going to do better than it. Use malloc. If you need speed then just allocate space not at run time. – Voltage Spike Mar 25 '17 at 5:30

The problem is not in using malloc() itself, the problem is with allocating and freeing memory chunks of arbitrary size repeatedly. If you only perform the allocation once and never free the block without restarting the device then you won't run into this problem.