Re: Allocatable arrays in derived types
- From: "Jugoslav Dujic" <jdujic@xxxxxxxxx>
- Date: Tue, 29 Apr 2008 12:24:18 +0200
Let me expand a bit on Richard's comment
relaxmike wrote:
| Hi,
|
| I don't remember exactly where I read it on this forum,
| but I remember that the difference between allocatable and pointer
| arrays is that, when an allocatable array goes out of scope,
| it is automatically deallocated.
| A pointer which goes out of scope is not automatically deallocated,
| because it may happen that another pointer keeps a reference
| to the pointee, so that an automatic deallocation would lost
| the reference.
| This is the main reason for the overhead of a allocatable
| array (and is also the main reason for some bugs in the
| implementation of allocatable in fortran compilers, which is
| tricky in complicated situations, like derived type, recursive
| function, etc...).
No. The overhead of an allocatable array in a typical implementation
is exactly the same as the one for a pointer of the same rank. And
in turn, those "overheads" are [tend to be] the same as for passing
and handling an assumed-shape array.
The primary cause of the overhead is complexity of Fortran arrays:
they can have multiple dimensions; they may start at index other
than default (1); they are of known size; the may have non-unit
strides... etc. Not all Fortran array types have all those properties
(e.g. ALLOCATABLEs cannot have non-unit stride), but it's convenient
for compiler writers to implement them using the same data structure
(known as "array descriptor" or "dope vector"). Those 7 or 8
dwords typically contain the starting address, a couple of flags,
lower bound, upper bound or size, and stride per each dimension.
Note that it's not releated with "bookkeeping" in "reference
counting" sense of the word. Fortran does not require (nor
common implementations perform) garbage collection, i.e.
"bookkeeping" how many pointers use the watched memory and
cleanup when the count reaches zero. Such bookkeeping would
probably have to be done outside of the array descriptors
anyway (but I'm not an expert on that).
--
Jugoslav
___________
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
.
- References:
- Allocatable arrays in derived types
- From: Gib Bogle
- Re: Allocatable arrays in derived types
- From: Arjen Markus
- Re: Allocatable arrays in derived types
- From: relaxmike
- Allocatable arrays in derived types
- Prev by Date: Re: GUIs with Dislin -more examples
- Next by Date: Re: Allocatable arrays in derived types
- Previous by thread: Re: Allocatable arrays in derived types
- Next by thread: Re: Allocatable arrays in derived types
- Index(es):
Relevant Pages
|