Best way to implement variable size array

I see that the only container types in Monkey C are Arrays and Dictionaries.

I want to generate a 1-D array, but for it to resize as I add values, similar to a List type in C#.  What is the best way to do that?  Perhaps I am better off just using a fixed sized array?  Application is looking for ANT devices and adding to list as a background scan finds them.

Thanks.

  • var a=[];

    for(var i=0;i<10;i++) {a.add(i);}

    you're adding 10 things to an empty array, so the resulting length will be 10.

    When doing this you want to be careful with large arrays, as when you do an add(), it creates a new array of the original size+1 then copies the old array data to the new array and frees the original array, so for a period of time the array can take twice the amount of memory.

  • Sure, sometime the API is poor.

    I have created my own list (add insert remove clean) but I know my arrays contain not many data (see jim_m_58 note about memory).