i have some code where I use arrays to hold large amounts of data(sometimes over 1million data points), I use arrays because they can be dynamically defined in 2 directions and are able to insert values at a specific position. However I found that when I use Redim to change to dimensions of the array it creates a duplicate of the array in the RAM causing me to eventually run out of RAM. I have found that Erase can be used to remove the array and save RAM, then I can use Redim to create a new array. However this means I have no where to hold my data in the mean time, unless I create a second array and manually copy the data across.
Is there a way to Redim an array to without losing RAM but with a more efficient way of hold the data rather than manually copy to a new array and back again. Or is there another class I can use to hold the data instead of an array that fulfills the requirements above.
Please ask for sample code if you would like some.
Many thanks for your help
Using an array in this way is not very memory efficient.
You would be better to use a List(of T) Have a look at this answer for reasons why
In this case you can use a class to hold each data point. Using a List(of T) allows you to insert into the middle of the list without a copy of the entire data being created.