Hi, this is my first post so please let me know if I'm missing something.
I have an application where I need an array of variable size. It's okay if the contents of the array are lost while resizing.
Due to constrained size, I'm not using the std:vector Arduino library.
Currently I'm doing
int *myArr = new int [first_size]();
myArr = {assign values}
//// Use in Code ////
delete [] myArr;
myArr = new int [second_size]();
//// Cycle Continues ////
I'm not familiar with dynamic memory allocation on Arduino, is this method okay?
Could it lead to any problems over long term use?
peaboard:
I'm not familiar with dynamic memory allocation on Arduino, is this method okay?
Could it lead to any problems over long term use?
I don't know how to do it because dynamic memory allocation is a risky business when you have only 2K of SRAM and no supervisory operating system to stop silly things from happening.
Why not just allocate an array that is big enough for your needs and under-use it some of the time?
As there can only be one program running on an Arduino there is nothing that can make use of the memory that might be released.