Re: Fortran and .NET (C#)



Richard E Maine wrote:
Let me repeat for the second time (at least) in this thread, and not counting many times in previous thready. You *CANNOT* leak memory because of a user error with Fortran allocatable arrays. That is an intentional part of the design of Fortran allocatables. It is so much a part of the design, that if you managed to find a way to do it, I am confident that it would be regarded as a bug in the standard and a fix would be published. In the many times I have explained this, not once has anyone come up with a code sample to contradict it.

It occurs to me that one could perhaps argue that Fortran allocatable arrays use a simplistic form of reference-counting garbage collection that can be implemented with zero cost at compile time. Namely, the language does not permit more than one "pointer" (by which I mean allocatable array variable, not a real pointer) to refer to a given piece of memory allocated as an allocatable array, and therefore, when a "pointer" is dereferenced (by going out of scope, or whatever), the compiler can assume the reference count has gone to zero and thus deallocate the memory.


I doubt that this is a helpful way of looking at things, however.

- Brooks


-- The "bmoses-nospam" address is valid; no unmunging needed. .



Relevant Pages

  • Re: allocatable and pointer in a type
    ... allocatable or pointer parameters use memory. ... they are not allocate! ... Thus, in order to find out exactly how it reports the use memory, you will need to read your vendor documentation. ... Third, allocatable arrays as components of derived types, a Fortran 2003 feature, occupy memory regardless of whether the allocatable array is actually allocated. ...
    (comp.lang.fortran)
  • Re: Unidentified memory leak
    ... I think that if the array is an ALLOCATABLE array, it can't leak ... you can just run without having a lot of memory: ... SUBROUTINE S1 ...
    (comp.lang.fortran)
  • deallocating via pointer associated with allocatable array
    ... Section 6.5.3 in Fortran 95/2003 explained: ... a pointer that is associated with the whole of a target that was ... this excludes a pointer that is associated with an allocatable array}" ... Does this mean the deallocate statement at the end of the following program ...
    (comp.lang.fortran)
  • Re: ALLOCATABLE or POINTER
    ... pointer to an array or an allocatable array? ... I think that any Fortran programmer understands why it is ... possible to replace a dummy normal argument either by a actual pointer ...
    (comp.lang.fortran)
  • Re: ALLOCATABLE or POINTER
    ... pointer needs to be associated to an allocatable array. ... run-time error should issue: here this is simply a programmer ... Imagine passing a pointer that points to a slice of a static array to an allocatable dummy argument with INTENT. ...
    (comp.lang.fortran)