MOVE_ALLOC in Fortran 2003
Tuesday, 8. May 2007, 14:46:10
Just quote as follows:
This lets you move the “allocation” of one array (with its data) to another, the original array now being unallocated. With this, expanding an array requires one copy and two arrays allocated for a while, but it saves a second copy that would be required without it.
Let’s say you have an array A that you want to double its size while preserving the original data.
Without MOVE_ALLOC you’d do this:
OLD_SIZE = SIZE(A)
ALLOCATE (TEMP_ARRAY(OLD_SIZE)
TEMP_ARRAY = A ! First copy
DEALLOCATE (A)
ALLOCATE (A(2*OLD_SIZE))
A(1:OLD_SIZE) = TEMP_ARRAY ! Second copy
DEALLOCATE (TEMP_ARRAY)
With MOVE_ALLOC you can do this:
ALLOCATE (TEMP_ARRAY(2*SIZE(A))
TEMP_ARRAY(1:SIZE(A)) = A
CALL MOVE_ALLOC (TEMP_ARRAY, A)
! TEMP_ARRAYis now unallocated
You say you are using “Visual Fortran” but don’t provide further details. MOVE_ALLOC is supported in Intel Visual Fortran 9.1.028 and higher, not in Compaq or Digital Visual Fortran. For Intel Visual Fortran, you’ll currently find it described only in the Release Notes and not the regular manuals.
Steve









