With arrays in the gigabytes making little additions can get really expensive, and big additions can require a huge memory bump for the temporary arrays too. I was thinking part of the reason to have MOVE_ALLOC would be efficiency, as this would work too
subroutine mergegrid(grida,gridb) ! assuming same number of rows in both
real, allocatable :: grida(:,:)
real :: gridb(:,:)
integer :: c1, c2, r1, r2
associate( r1=>size(grida,dim=1), r2=>size(gridb,dim=1), &
& c1=>size(grida,dim=2), c2=>size(gridb,dim=2) )
grida=reshape([grida,gridb],[r1,c1+c2]) ! Allocate bigger grid
end associate
end subroutine mergegrid
I know of several programs where the user is supposed to guess an appropriate array size for his problem but if he guesses wrong the program will automatically keep doubling the array size every time it gets filled, and if the array is in the GB, making the new one and still having the old one gets pretty expensive.
I know of others where it just adds a row at a time, and that can really thrash things; although sometimes a smart compiler can make that a relatively cheap operation; but if it does so by creeating a non-contigious array that can have other draw-backs.
So since I am “discovering” MOVE_ALLOC what would be the purpose for it when I could just replace it with something like the above, I wonder?