When to use allocatable arrays?

I use allocatable arrays for all the intermediary variables within a function/subroutine, even when they don’t need to be resized/reshaped. Is there a rule of thumb regarding when to use allocatable arrays?


My rule of thumb is to make arrays allocatable when I can’t determine their shape ahead of time, or if I expect their shape to change during the life of the program.

1 Like

It isn’t clear exactly what is the question. Do you mean instead of arrays dimensioned with fixed dimension, or automatic arrays with variable dimensions, or pointer arrays which can also be allocated? Are you talking about dummy argument arrays, or local arrays, or module arrays? All of those types of arrays have distinct characteristics, and you will probably use all of them at some time or another.