Jack Scheible wrote:
>
> That is why we programmers don't have to worry about fragmenting
> memory, until we reach the 4 gig limit. The OS writers have already
> solved the problem.
>
I can see it's diffucilt to convince you... :-)
Just test the small attached F90 program, which recursively
reallocate a 1D tab (sizes are the Fibonacci serie),
and tell me what are the result and your conclusions.
Here is the output I have on a RS6000:
hugonnet% a.out
total allocated = 1024
total allocated = 2048
total allocated = 3072
total allocated = 5120
total allocated = 8192
total allocated = 13312
total allocated = 21504
total allocated = 34816
total allocated = 56320
total allocated = 91136
total allocated = 147456
total allocated = 238592
total allocated = 386048
total allocated = 624640
total allocated = 1010688
total allocated = 1635328
total allocated = 2646016
total allocated = 4281344
total allocated = 6927360
total allocated = 11208704
realloc of 18136064 failed
dealloc of a --> total allocated = 0
alloc of 29344768 (= 11208704 + 18136064 ) possible!
--
Pierre Hugonnet Seismic Data Processing R&D
COMPAGNIE GENERALE DE GEOPHYSIQUE
mail: 1 rue Leon Migaux phone.....(33) 164 47 45 59
91302 MASSY fax.......(33) 164 47 32 49
FRANCE [log in to unmask]
My opinions are not necessarily those of CGG (nor those of JPII)
PROGRAM toto
IMPLICIT NONE
INTEGER :: fibo(3) = (/1,1,0/)*1024
INTEGER :: ierr, l
REAL, POINTER :: a(:)
allocate( a(fibo(1)) )
CALL reallocate(a, fibo(2), STAT=ierr) ; IF (ierr /= 0) STOP
DO
write(*,*)
fibo(3) = fibo(1)+fibo(2) ; fibo(1) = fibo(2) ; fibo(2) = fibo(3)
l = size(a)
write(*,*)"total allocated =",l
CALL reallocate( a, fibo(3), STAT=ierr)
IF (ierr /= 0) THEN
write(*,*)"realloc of ",fibo(3)," failed"
deallocate(a)
write(*,*)"dealloc of a --> total allocated = 0"
allocate( a(fibo(3)+l), STAT=ierr)
IF (ierr == 0) THEN
write(*,*)"alloc of ",l+fibo(3),"(=",l,"+",fibo(3),") possible!"
ELSE
write(*,*)"alloc of ",l+fibo(3),"(=",l,"+",fibo(3),") failed"
END IF
STOP
ELSE
CYCLE
END IF
END DO
CONTAINS
SUBROUTINE reallocate(a,new_size,stat)
REAL, POINTER :: a(:), temp(:)
INTEGER, INTENT(IN) :: new_size
INTEGER, INTENT(OUT) :: stat
INTEGER :: ncopy
allocate(temp(new_size), STAT=stat)
IF (stat == 0) THEN
ncopy = min(size(a),new_size)
! temp(1:ncopy) = a(1:ncopy)
deallocate(a)
a => temp
END IF
END SUBROUTINE
END
|