MRC-CSO-SPHSU / LoneParentsModel.jl

An initial implementation of an ABM for social and child care
0 stars 4 forks source link

Optimal data structure for kinship.children #81

Closed AtiyahElsheikh closed 2 years ago

AtiyahElsheikh commented 2 years ago

At the moment it is initialized as an empty array. Should that be rather defined as a linked list?

mhinsch commented 2 years ago

Why?

AtiyahElsheikh commented 2 years ago

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).

mhinsch commented 2 years ago

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.