Re: Allocatable array of allocatable defined types?
- From: Mark Morss <mfmorss@xxxxxxx>
- Date: 30 Apr 2007 09:11:13 -0700
On Apr 30, 11:21 am, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
Mark Morss <mfmo...@xxxxxxx> wrote:
On Apr 30, 10:21 am, "Michael Metcalf" <michaelmetc...@xxxxxxxxxxxxxx>
wrote:
type alloc
real, dimension(:), allocatable :: a1
real, dimension(:), allocatable :: a2
end type alloc
type(alloc), dimension(:), allocatable :: work
integer, parameter :: ll = 3
...allocate(work(2))
do i = 1, 2
allocate(work(i)%a1(ll), work(i)%a2(ll))
end do
It surprises me that you can allocate an array "before" the size of
its elements is known. Apparently the compiler looks ahead and
figures this out?!
No. It isn't a matter of looking ahead, which wouldn't be possible
except in the most trivial cases. When the derived type array is
allocated, the elements are initially all created as unallocated. There
is no data space for them at all until they are, in turn allocated.
I suspect you are not seeing that the implementation of an allocatable
component will look a lot like a pointer in that the actual data space
for the component will be elsewhere in memory rather than embedded in
with the rest of the components. Somethingh that looks much like a
pointer is all that is in the memory space with with the rest of the
components.
The low-level use of constructs like those of pointers is "hidden" from
you. The compiler takes care of the details in a way that works out much
better than if you have to directly use pointers yourself (as does much
code from days before the TR was widely supported, which has only been
relatively recently).
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
That's very useful to know, thank you.
.
- Follow-Ups:
- Re: Allocatable array of allocatable defined types?
- From: Paul van Delst
- Re: Allocatable array of allocatable defined types?
- References:
- Allocatable array of allocatable defined types?
- From: Mark Morss
- Re: Allocatable array of allocatable defined types?
- From: Michael Metcalf
- Re: Allocatable array of allocatable defined types?
- From: Mark Morss
- Re: Allocatable array of allocatable defined types?
- From: Richard Maine
- Allocatable array of allocatable defined types?
- Prev by Date: Re: Question about KIND
- Next by Date: Re: About Migrating from F77 to F95
- Previous by thread: Re: Allocatable array of allocatable defined types?
- Next by thread: Re: Allocatable array of allocatable defined types?
- Index(es):
Relevant Pages
|
|