Closed AtiyahElsheikh closed 2 years ago
Why?
So I don't know how is it in Julia. But to my understanding, when an array is initialized, an initial size (probably according to a heuristic) is pre-determined. So this could imply that: so many memory is pre-allocated and not used. Moreover, the unused memory is sequential implying inefficient memory management during simulation (e.g. more data is being brought in and out of cache).
With the number of elements we are talking about (a couple) a linked list would probably be more wasteful (not to mention slower). Most implementations of vector start with 0 memory allocated and double the memory every time they run out (I assume Julia does the same). Since vectors of non-plain structs (e.g. mutable) are effectively vectors of pointers this means in the worst case scenario (5 kids, vector size 8) a waste of three machine words. That's probably less than the overhead of a linked list.
At the moment it is initialized as an empty array. Should that be rather defined as a linked list?