I want to use the Ocaml array instead of list because the memory footprint for array is less than the list.
I have to store big information in array. I am using Array.append to add a new element.
However, Ocaml documentation for Array.append says:
Array.append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2
It returns a fresh array without modifying the existing array.
After appending many items in the array, array.ml append function throws Out-of_memory error.
Is there any other alternative to this function? [Or perhaps my understanding of Array module is not good]
It’s hard to give you a sound suggestion because we don’t know what you’re trying to achieve.
If you know or can guess the size of the array in advance, just start with a “big enough” array.
Otherwise you might want to consider libraries that implement “dynamic arrays”.