Re: Allocatable arrays in derived types



relaxmike wrote:
| On 29 avr, 11:26, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
|| That is *A* difference. It is certainly not *THE* difference. [...]
|| No. [...]
|| Not typically. [...]
|| No. [...]
|
| Despite appearances, I think that we do not disagree that much !
<snip>
| This is an abstract :
|
| extra_mem ()
| {
| struct array1_integer(kind=4) mydata;
| static integer(kind=4) options.0[7] = {68, 255, 0, 0, 0, 1, 0};
| mydata.data = 0B;
| _gfortran_set_options (7, (void *) &options.0);
| {
| void * D.567;
| mydata.dtype = 265;
| mydata.dim[0].lbound = 1;
| mydata.dim[0].ubound = 10;
| mydata.dim[0].stride = 1;
| [... with a "D.568 = __builtin_malloc (40);" and "D.567 = D.568;"]
| mydata.data = D.567;
| mydata.offset = -1;
| [...]
|
| We can see the dtype (data type ?), the lower bound 1, the upper
| bound 10 (what is stride ? what is offset) and the memory location
| is probably in mydata.data.

"Stride" is the last thingo in the array triplet, i.e. index
difference between subsequent array elements:

http://www-unix.mcs.anl.gov/dbpp/text/node84.html

"Offset" is an internal thingo, which is not essential, but can
speed up calculation. The point is to calculate it in advance,
so you can find the address of element x = A(1,2,3) faster, like:

*x = A(offset + 1 + 2*dim[1].ubound + 3*dim[2].ubound)

Without offset, you would have to involve lbounds into play
in general case, and every array access would have to involve
a couple of extra operations. (My math above is almost certainly
wrong, but you get the idea).

| If we... compare the intermediate code with allocatable and pointer
| versions, one can see that only the "allocatable" version contains
| the following code, near the end of the source :
|
| if (mydata.data != 0B)
| {
| __builtin_free (mydata.data);
| }
| mydata.data = 0B;
|
| which clearly shows how gfortran deallocate the array
| before exiting from the subroutine.

Exactly. Just as expected.

--
Jugoslav
___________
www.xeffort.com

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



Relevant Pages

  • Re: Array descriptors
    ... There seem to be two ways of implementing the array descriptors ("dope ... where the base_address plus the offset defines the first memory ... Sun Fortran uses a third option. ... origin, your base address, and a virtual origin, the address ...
    (comp.lang.fortran)
  • Re: fast dictionary search algorithm
    ... >> requested word's meaning in the shortest time possible. ... >Im no expert but I would have thought a binary search for a hash from ... using it as an array offset. ...
    (comp.programming)
  • Re: Offset/match returns #value error
    ... Yes the formula in the original post works fine using INDEX instead of ... OFFSET. ... The other formulas come from elsewhere in the workbook and were ... What I was doing in my last post was building an array using INDEX as follows: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Library Design, f0dders nightmare.
    ... demo mistake but I suggest to you that a sequence of blunders on this ... Feed it through your parser to get the offset of each ... offset to its appropriate place in the array of pointers and when you ... dividing the byte count by two to determine the maximum pointer array ...
    (alt.lang.asm)
  • Re: Assignment: Print 2D array
    ... Then create two functions for printing the 2D array. ... int column = 0; ... int offset = 0; ... Flash Gordon, living in interesting times. ...
    (comp.lang.c)