Re: Overloading OPERATOR(+): my usage causing memory leaks.



On Nov 3, 3:10 pm, Paul van Delst <paul.vande...@xxxxxxxx> wrote:
Richard Maine wrote:
Paul van Delst <paul.vande...@xxxxxxxx> wrote:

Richard Maine wrote:

P.S. As far as I can see, your defined assignment does the same thing as
the intrinsic assignment would...
Wha..? You mean, sans my defined assignment routine, doing
  a = b
where a and b are derived types with allocatable components, the compiler
should allocate the components of the lhs before doing the assignments?

Yes.

Remember I'm still using f95+tr15581 compilers. I am rearranging things
for an easy switch to using type bound procedures once f2003 compilers
become routinely available. Does f95+tr15581 do more behind-the-scenes
housekeeping than I thought?

Yes. From N1379 (as close as I have handy to the final version of the
TR)

    For intrinsic assignment of objects of a derived type containing an
    allocatable array component, the allocatable array component of the
    variable on the left-hand-side receives the allocation status and,
    if allocated, the bounds and value of the corresponding component of
    the expression.

It then goes on to cover some fine points about possible optimizations
of and the effects of the allocatable component also being a target.

I did not know that. Let's see what happens in my test program when I remove my defined
assignment function so that intrinsic assignment is used instead.....

...modifying...compiling...running....

Holy crap.... the memory leaks have disappeared! Let me test the actual code I'm working
on......

OMG! No memory leaks there either! All 8000 tests passed, 88.9MB deallocated!

So it would appear removal of my assignment function did, in fact, allow the compiler to
optimise the process in the add operation when intrinsic assignment is used. This is
brilliant. Not only have the memory leaks gone, but I've eliminated the need for an
assignment procedure.

Thanks so very much.


Paul,

Some of these memory leaks with gfortran are well-known. Paul Thomas
had developed a -fcheck=memleak (or some such named option) to help
track down leaks in not only user code but also gfortran. Sadly, that
patch
was lightly tested and withered in the mailing list. There are plans
to
revamp the internal representation in array descriptors. It is hoped
that
some (if not all) of these leaks will be caught at that time.

--
steve

.



Relevant Pages

  • Re: Pointer use/ mem.leak gfortran
    ... Please post this to the gfortran list and submit a report to gcc ... memory leaks from failure to free temporary copies. ...   REAL:: tt ...   ALLOCATE(buffer(y,z,dmn,6)) ...
    (comp.lang.fortran)
  • Re: gfortran problem
    ... conform or weren't allocated before the assignment. ... otherwise no automatic reallocation is ... Syntax error in character length specification at ... Syntax error in ALLOCATE statement at ...
    (comp.lang.fortran)
  • Re: Non-Blocking versus blocking
    ...   always @ ... must execute the two blocks sequentially at the ... But when we use nonblocking assignment, ...
    (comp.lang.verilog)
  • Re: Serialization of derived data types
    ... That's part of the definition of intrinsic assignment. ... components are done by pointer assignment. ... association one does not allocate memory. ...
    (comp.lang.fortran)
  • Re: integer and floating point casts queries
    ...     double d; ... example, float and int), then the value of the operand that is of ... If the left hand side and the right hand side of the assignment ... converting the long value 33 to an int. ...
    (comp.lang.c)