Dynamic Array Creation in ESME HVAC with EEPROM Variable

I’m currently working on a project where I need to create an array in ESME HVAC, and I want the size of this array to be determined by an EEPROM variable instead of a fixed constant. This would allow for more flexibility in my application, as the array size can be adjusted based on different configurations or inputs. However, I’m running into some challenges during the implementation process.Here’s what I’ve tried so far: I declared an EEPROM variable called Num_Units of type UINT. My goal is to use this variable as the upper bound for the array size. When I compile the code with Num_Units set to a specific value, like 10, the array is created successfully with a size of 11 (indices 0-10). This works perfectly fine, but I need the array size to be dynamic based on the value of Num_Units.I attempted to declare the array within an ST program, but the system doesn’t allow me to do so. It seems that the array size needs to be known at compile time, which is conflicting with my requirement for a dynamic size. I’ve also tried using Num_Units directly in the array declaration, but that results in a compilation error.After some research, I found that dynamic memory allocation might be the solution here. By using functions like malloc, I can allocate memory for the array at runtime based on the value of Num_Units. This approach would allow me to create an array of the exact size needed without knowing it beforehand.Here’s a rough idea of how I could implement this:cUINT *myArray;UINT arraySize = Num_Units + 1; // Adding 1 to include index 0myArray = (UINT *)malloc(arraySize * sizeof(UINT));if (myArray == NULL) { // Handle memory allocation failure Error_Handler();}// Use the dynamically allocated arrayfor (UINT i = 0; i < arraySize; i++) { myArray[i] = 0;}// Remember to free the allocated memory when donefree(myArray);This code snippet demonstrates how to dynamically allocate memory for an array based on the value of Num_Units. It’s important to check if the memory allocation was successful and to free the memory when it’s no longer needed to prevent memory leaks.I’m still a bit unsure about the best practices for memory management in this context, especially within the constraints of the ESME HVAC environment. I would appreciate any advice or tips on implementing this effectively. Additionally, if there are any potential pitfalls or alternative approaches, I’d love to hear about them.Overall, while dynamic memory allocation seems like the right path, I’m looking for confirmation and guidance to ensure I’m implementing this correctly and efficiently.