Re: Allocatable attribute on derived type components







How ever i still cannot understand
1) Since what would happen
Arjen Markus wrote:

Thanks for the help..

gaurav schreef:

Hi,

The F003 standard introduced allocatable attribute on derived type
components. The component with allocatable attribute has to be
allocated seperately using allocatable statment.

However, I could not understand the memory layout of the object of such
derived type object.

For example, consider the following

type drv
integer :: x(10)
real , allocatable :: y(:, :)
end type drv

and then an object obj is defined.

type (drv) :: obj

Can any one help me to understand the memory layout of "obj"? What
would be the size of obj?

Also, what would be the memory layout in case if the derived type is
sequenced?


The feature you describe is available in many Fortran 95 compilers too,
as there is a technical report on it.

But layout should not matter at all - and if it does, it will depend
entirely on the
hardware and the Fortran compiler in question.

My guess is that this is/will be implemented in a very similar way
as for pointer components, that is, "somewhere" a block of memory
will be allocated. It's position is unrelated to the position of "obj".

But then what difference would this create from pointer attribute on
derived type component. since the memory allocation is similar to
pointer one....and also if i just allocate pointer component instead of
aliasing it....this would be like i am using an allocatable
component....why did they provide it altogather..since functionality of
allocatable component can be done with pointer component...also



As to the size, the following code fragment might give a clue:

character(len=1), dimension(1) :: byte

write(*,*) size( transfer(obj,byte) )

Can you explain why you want to know?

Well i was thinking of implementing this in some compiler...

Regards,

Arjen

.



Relevant Pages

  • Re: Allocatable attribute on derived type components
    ... allocatable component can be done with pointer component... ... Functionality comprises more than memory layout. ... So does allocation and deallocation. ... I'll defer details, as they are covered elsewhere, I'm short on time, ...
    (comp.lang.fortran)
  • Re: xlf Fortran Oddity
    ... Presumably you mean allocatable components of a derived type. ... allocation; that isn't quite the terminology used by the standard, ... that's a lot of overhead (and is not supported by any current compilers ... you can't have "ragged arrays" (arrays whose number of rows is different ...
    (comp.lang.fortran)
  • Re: how to use derived types with allocatable elements for I/O
    ... Even if I/O of a derived type with an allocatable component worked, ... direct access would be a problem because direct access requires ... for the largest plausible allocation, but that would likely be pretty ... They do require a fair amount of bother to set up, but you only have to do ...
    (comp.lang.fortran)
  • Re: (MS-)DOS PC on a microcontroller??
    ... memory block of zero bytes. ... The pointer returned if the ... Each such allocation shall yield a pointer to ... support malloc/calloc requests for 0 bytes and whether or not the ...
    (comp.arch.embedded)
  • Re: allocating memory for array of pointers to char
    ... >> checking up on allocation and so on, the types of your objects are ... > pointer inside a linked-list element. ... > typedef struct listelem_t { ... "value" is a pointer to an array of unknown length. ...
    (comp.lang.c)