In embedded systems, the use of dynamic allocation is strongly discouraged. MISRA C do not allow using malloc and calloc because of their unexpected behaviour. My question is: How do you handle memory allocation when you have no idea how much space you need ? How do you initialise an array before using it ? In the example below, is it really better to allocate 1000 values and end up using 30 values because you don't know how many values you really need ?
#define MY_ARRAY_MAX_SIZE 1000/*** * some code ...*/// Inituint8_t myArray[MY_ARRAY_MAX_SIZE]; // Approach 1uint8_t myArray[MY_ARRAY_MAX_SIZE] = {0} // Approach 2/* OR */memset((void *)myArray, (uint8_t)0, MY_ARRAY_MAX_SIZE * sizeof(uint8_t)); // Approach 3