Giorgio Pastore wrote:
> Are there general guidelines about when it is better to use pointer and
> when allocatable arrays ? Is there any book or document discussing pros
> and cons of such implementation choices ?
I am not aware of one. But to me the guideline is: Only use pointer if
it is actually needed. Pointers differ from allocatables in the
following important aspects (as far as my usage goes):
1) They can be aliased with other pointer or target arrays. So if you
need to look at the same data in two different ways, or from two
different data-structures, than you will need a pointer.
2) Pointers can be non-contiguous: So if you want to only look at a row
of a matrix as a 1D array (from another scope/data-structure), then you
need a pointer. I use this to extract a subcomponent of an array such as
extracting an array pointer for just the positions of velocities from a
collection of atoms in a simulation.
3) Pointers can easily switch their association status without releasing
the memory. So if you need to have dynamic data structures like trees
where you want to frequently swap links but not have to pay the price of
memory allocation every time, or you want the pointee to remain in
existence, you will need pointers.
4) Memory for pointers can be allocated externally, say, in C.
Maybe others can add to the list.
5) Prior to F95 there were no allocatable components/dummies, so if you
use a compiler that is behind on modernity (there are a couple
unfortunately), use pointer.
Best,
Aleksandar
--
__________________________________
Aleksandar Donev
Complex Materials Theory Group (http://cherrypit.princeton.edu/)
Princeton Materials Institute &
Program in Applied and Computational Mathematics
@ Princeton University
Address:
419 Bowen Hall, 70 Prospect Avenue
Princeton University
Princeton, NJ 08540-5211
E-mail: [log in to unmask]
WWW: http://atom.princeton.edu/donev
Phone: (609) 258-2775
Fax: (609) 258-6878
__________________________________
|