I can reallocate an allocatable variable or array without the explicit deallocate/allocate procedure as explained in Automatic array allocation upon assignment in Fortran if my compiler is Fortran 2003 compliant. E.g.
integer, allocatable :: i(:)
i = [1,2,3]
i = [1,2,3,4,5]
versus the old (Fortran 90) way:
if( allocated(i) ) deallocate(i)
allocate(i(3))
i = [1,2,3]
if( allocated(i) ) deallocate(i)
allocate(i(5))
i = [1,2,3,4,5]
What or the adventages and disadvantages of this newer technique? It's certainly much more concise code than the old way. But are there reasons to prefer the old way? I still see the old way in code examples much moreso than the new way, but maybe it's just because Fortran 90 is still used more than Fortran 2003.
As a quick timing check, I looped the above code 100,000,000 times under gfortran 4.8.5 and found that the newer way also seems to be faster, running in about 4 seconds (new way) vs 6 seconds (old way). Conversely, in the comments below @roygvib gets essentially the opposite result with gfortran 8.2.
Also, note this recent discussion of the issue here: Fortran Discussion Group