J.L.Schonfelder wrote:
> but I have a problem with
> ALLOCATE(Q(N:M))
> P=>Q
> DEALLOCATE(P)
> This is likely cause a problem since as far as I can see this leaves
> Q dangling.
This is always a problem with pointers. Not allowing one to transfer an
allocation from one object to another is much more serious of a
problem, since leaks will be happening that CANNOT be reversed. Note
that the new MOVE_ALLOC will nullify Q when the allocation is moved to
P, but of couse for pointers we cannot ask that much.
Being able to transfer the allocation from one pointer to another is
essential in having a useful derived type intrinsic assignment, which
does a shallow copy for pointers, and a deep one for allocatable. If a
shallow copy is needed for allocatables, one can use the new intrinsic
MOVE_ALLOC inside a defined assignment to override the default.
It all makes a lot of sense to me. But, yes, deallocating
P=>Q(:)
does not seem justified to me.
I just wish our standard actually said that...
Best,
Aleks
|