Re: Overloading OPERATOR(+): my usage causing memory leaks.
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Tue, 3 Nov 2009 12:57:22 -0800
Paul van Delst <paul.vandelst@xxxxxxxx> wrote:
I'm overloading an elemental ADD function to OPERATOR(+) and I'm getting
Imemory leaks when apply it to array arguments. Scalar arguments cause no
Iproblem.
My question is: what in the code could be causing these memory leaks?
In the test program, if I comment out the
c = c + d
line, i.e. adding the array structures, then I get no memory leaks. I made
all the routines in question elemental, so they should work with array
arguments, right?
[code and valgrind output elided]
I can't get anything from the valgrind output, probably because I've
never used valgrind. I'm not a beer drinker anyway. :-)
I'd guess it to be a compiler bug, and I can even roughly guess where.
I'm not at all sure, but it seems a good enough guess to mention.
I think it is the compiler failing to remove a compiler temporary. Your
addition of c+d is quite likely to generate a temporary array for that
sum. Then that temporary array will be assigned to c (using your defined
assignment). The compiler *OUGHT* to deallocate the temporary after the
assignment, but it seems a good candidate for something some compilers
might miss.
P.S. As far as I can see, your defined assignment does the same thing as
the intrinsic assignment would... except that the compiler might have a
better chance of being smart about optimizing the intrinsic one, whereas
is seems likely to just "punt" and naively invoke your defined one. Of
course, if this is just a simplification of code that involves other
things, that would be different. Or perhaps variants of this are also
intended to work with pointer components instead of allocatable ones;
pointer components tend to need more of this kind of stuff to fake what
allocatable ones do intrinsically.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Overloading OPERATOR(+): my usage causing memory leaks.
- From: Paul van Delst
- Re: Overloading OPERATOR(+): my usage causing memory leaks.
- References:
- Overloading OPERATOR(+): my usage causing memory leaks.
- From: Paul van Delst
- Overloading OPERATOR(+): my usage causing memory leaks.
- Prev by Date: Re: Fortran vs. Octave/Matlab
- Next by Date: Re: Fortran vs. Octave/Matlab
- Previous by thread: Overloading OPERATOR(+): my usage causing memory leaks.
- Next by thread: Re: Overloading OPERATOR(+): my usage causing memory leaks.
- Index(es):
Relevant Pages
|