Dynamic memory, allocs and pointers
From: Anthony (Anthony_at_work.nl)
Date: 06/29/04
- Next message: Jugoslav Dujic: "Re: Mixed Language DLL"
- Previous message: Gerry Thomas: "Re: Accuracy of tan()?"
- Next in thread: Jan Vorbrüggen: "Re: Dynamic memory, allocs and pointers"
- Reply: Jan Vorbrüggen: "Re: Dynamic memory, allocs and pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Jun 2004 08:52:00 +0200
Hi,
In example the routine 'pointers' is used for wrapping
F90's ALLOCATE with some proper error handling included.
file test.f:
program test
use pointers_mod
real, allocatable, dimension(:) :: a ! is this the
right declaration ???
n = 10
call pointers(a,n)
a = (/(i,i=1,n)/)
write(*,*) ' Memory used so far ',memory_used
end program test
file pointers.f:
module pointers_mod
integer :: memory_used=0
contains
subroutine pointers(a,n)
integer :: n, error
real, dimension(:), allocatable :: a
allocate(a(n), stat=error)
memory_used= memory_used+ n
if (error /=0) stop 'Memory problem'
end subroutine pointers
end module pointers_mod
In Visual Fortan (MS Dev Studio) this works nice, but I have
doubt about the declaration of array 'a' in the main
program.
Or must this better be replaced by declaration
real, pointer, dimension(:) :: a
from the idea that routine 'pointers' returns a pointer to
the just allocated array. Something you have in C programs.
I know that pointers in F90 work more like aliases, so are
different the 'real pointers' in C.
At the other hand, the example above works for both
declarations, thus it gives the expected result.
Some help would be nice.
Thanks.
Anthony.
- Next message: Jugoslav Dujic: "Re: Mixed Language DLL"
- Previous message: Gerry Thomas: "Re: Accuracy of tan()?"
- Next in thread: Jan Vorbrüggen: "Re: Dynamic memory, allocs and pointers"
- Reply: Jan Vorbrüggen: "Re: Dynamic memory, allocs and pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|