Re: Memory Leak Problem



On Jun 18, 4:06 pm, babak...@xxxxxxxxx wrote:
Hey Guys,

Just to start off, this is my first time on this forum, so I aplogize
in advance.

Before I get into my problem, I'm not a programmer, I'm a stats
masters student and have to write some code to
carry out my research, hence the poor programming structure.

That being said, I have, what I believe to be a memory leak problem. I
think I have located the problem, but Im not sure how to fix it.

I have an iterative process that carries one for about a 1000 times.
And each iteration I generated about 700000 random numbers. I have
used the ALLOCATE() function before the iterative techniques, but when
I have tried using the DEALLOCATE() function I get a segmentation
fault. The variable that contains these random numbers is a pointer,
and I have named it "rout." The random numbers come from a subroutine
too.  I have given a link to the code (which is not very long at all),
and if someone has any suggestions I am truly greatful, as this
problem has frustrated me for too long now!

http://www.uoguelph.ca/~bhabibza/epidemic.f ;        <- main code
http://www.uoguelph.ca/~bhabibza/subrng.f ;           <- subroutine to
produce random numbers

Thanks in advance,

Babak

1. Using .f seems odd for free-format source.
2. Variable P has default type of REAL. This causes a problem with my
compiler (g95) which does not allow REAL valued array indexes. Perhaps
P was meant to be declared INTEGER. Adding IMPLICIT NONE would have
helped here.
3. ALLOCATE(rout(n)) in the main program, where N has no defined
value, has already been mentioned.
4. Suggest INTEGER,PARAMETER for the "magic number" 21.
5. seed=aint(harvest*2.0e0**31) Why not the simpler 2**31?
6. Why the call to RNG in the main program when none of the 700,000
values generated are used?
7. Arrays vp_names and vp are unchanged as the program runs.
Initializing vp inside a loop does not make sense. Why not use DATA
instead?
8. Variables a & b are REAL but are really used as INTEGERS. Assigning
an INTEGER to a REAL variable is actually allowed.
9. Suggest SELECT CASE instead of IFs when dealing with individuals(i)
%status. (status = 0, 1 or 2 or ?)
10. When testing %status and %dummy_status near the end of the
program, all of the actions taken in the three cases are the same.
Suggest a compound conditional here

IF ( ( .AND. ) .OR. ( .AND. ) .OR
( .AND. ) ) ....

11. You are generating 700,000 random numbers at one time. How many do
you actually use?
12. [I don't understand POINTER in Fortran very well.] Is it standard
to use rout, which has a pointer attribute, as an argument and then
ALLOCATE it inside your subroutine? Why not a fixed size array? I see
no advantage in your program to making ROUT come and go.

- e

.



Relevant Pages

  • Re: Fast Image access for binarization
    ... Instead of indexing into the array on every iteration, use a pointer. ... I don't know if your compiler will perform this optimization already. ...
    (sci.image.processing)
  • Re: Variable length arrays
    ... gcc will ALSO produce different arrays for each iteration. ... If you print a pointer to the end of the array, ...
    (comp.lang.c)
  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)
  • Re: multi dimensional arrays as one dimension array
    ... please - where does the standard say that such a conversion ... Pointer conversion yields a pointer to the same object as ... exist only where there are array declarations. ...
    (comp.lang.c)
  • Re: Evaluating unary *
    ... 'arr' exists, ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... lea eax, ...
    (comp.std.c)