Skip navigation.

MOVE_ALLOC in Fortran 2003

When Steve Lionel answered on comp.lang.fortran about “how to rename an array”, He told in Fortran 2003 there’s a MOVE_ALLOC intrinsic subroutine/function which has been implemented in Intel Visual Fortran 9.1.028 and later.

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


why I teachSay Hi and Goodbye

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies