Re: F90 derived type component as array



kus@xxxxxxxx wrote:
| Sorry,
|
| is there in F90 some restriction(s) for using of components (which are
| really arrays) of derived types
| instead of arrays itself ?
|
| I.e. if I have for example something like
|
| TYPE twoarray
| real, dimension (:,:) ::A
| real, dimension (:,:) ::B
| END TYPE twoarray
|
| TYPE(twoarray), DIMENSION(100) ::struct
|
| - may I use struct(k)%B in any place where I may use simple
| 2-dimensional array ?

Yes. However, your syntax is not correct; the arrays have to
be either fixed-shape:

TYPE twoarray
real, dimension (42,55) ::A
real, dimension (19,38) ::B
END TYPE twoarray

or have pointer attribute:

real, dimension (:,:), POINTER ::A
real, dimension (:,:), POINTER ::B

which you can later ALLOCATE, or, under Fortran2003/TR15581,
allocatable attribute:

real, dimension (:,:), ALLOCATABLE ::A
real, dimension (:,:), ALLOCATABLE ::B

Most modern compilers support that, so I suggest you try it first.

Additionally, you can also use e.g. struct(:)%B(23,37) to refer to
all B(23,37) members of all structs (if you ever need it),
but you cannot use struct(:)%B(:,:) to refer to all B's in all
structs.

| BTW, do I understand correctly that (in reality) memory requirements
| for twoarray structure are
| simple size(A)+size(B), i.e. "mapping" to the memory of this type is
| simple "memory for A" and
| then "memory for B" w/o any "control" information ?

In reality, yes, that's right. POINTER and ALLOCATABLE components
introduce a tiny overhead, in order of magnitude of 20 bytes per
dimension (compiler-dependent).

--
Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.
.



Relevant Pages

  • Re: implementing an array based class
    ... Arrays take about 20 times less memory than structs or MyObject. ...
    (comp.lang.ruby)
  • Re: Array access at fixed memory address
    ... It was no problem to set it up in static memory ... accessing muli-dimentioned arrays and arrays of structs tied to a hard ... The size if the array elements depends somewhat on the compiler. ...
    (comp.arch.embedded)
  • F90 derived type component as array
    ... really arrays) of derived types ... END TYPE twoarray ... do I understand correctly that memory requirements ...
    (comp.lang.fortran)
  • memory leak in (?)... (redux)
    ... the mem leaks in our long-running tcl daemons. ... when actively exercised the app grows continuously. ... the mystery is that while our audit code does show us a couple of arrays ... and memory are checked and meanwhile externally, ...
    (comp.lang.tcl)
  • Re: StackOverflowException.
    ... The Status object monitors the ... so I'm really at a total loss as to where I'm leaking stack memory. ... private static extern bool EscapeCommFunction(IntPtr hFile, ... Good to know about arrays. ...
    (microsoft.public.dotnet.framework)