Re: Allocatable Arrays As Outputs



bonzaboy@xxxxxxxxx wrote:
(snip)

You can try using pointers instead (they are pretty simple to use in
f95). If you declare propertynames as a pointer, I.e. replace
'allocatable' with 'pointer', you can still allocate memory as you
have. Then you simply need to declare the variable in the calling
program to also be a pointer (same shape). You also have to use the
save attribute in the subroutine to ensure the memory isnt lost when
the subroutine exits.

The ALLOCATE statement has two uses. One to allocate an ALLOCATABLE
variable, the other to allocate the TARGET of a POINTER variable.
It is probably best not to mix the use of ALLOCATABLE and POINTER
together.

ALLOCATABLE variables are deallocated as appropriate when the
appropriate routine exits. POINTER targets allocated with
an ALLOCATE statement are not automatically deallocated.

If I understand the post above, there is no need for a SAVE
attribute.

-- glen

.



Relevant Pages

  • Re: Advice on how to return a list of values
    ... The caller passes a pointer to a previously allocated array of 64 ... My function allocates the array and returns it. ... well allocate that much space and be done with it. ...
    (comp.lang.c)
  • Re: Derived type - valued function with pointer member.
    ... If I understand what you want to do, the only reason you need the pointer attribute is because the allocatable attribute for derived type components didn't make it into f95. ... When I make the %vec's allocatable arrays instead, the program segfaults on calling vplus. ... I think the safer route is to create specific allocate and destroy functions for the vector data type and use those. ... Default is to test ALL the pointer members ...
    (comp.lang.fortran)
  • Re: Allocatable derived type with allocatable components in fortran 90
    ... N_cells with each cell containing particles. ... fit all data related to a cell within cache. ... The methods that involve allocatable or pointer components do not ... would be a mess (allocate a large target array elswehere and make all ...
    (comp.lang.fortran)
  • Re: Is There Any Reason to Even Use VC++ Anymore?
    ... If, for another reason, the calling function needs to allocate memory, ... It does this by taking a pointer to a ball object ...
    (microsoft.public.dotnet.languages.vc)
  • Re: C++ exception handling question [solved]
    ... I'm not a professional programmer, ... simulation code for my research in biodiversity. ... Doesn't realloc allocate new space, which means that the objects inside ... Then it returns a null pointer. ...
    (Debian-User)