freeing dynamic memory in the r.le programs
BAKERWL
BAKERWL at corral.uwyo.edu
Sun Jul 18 17:31:38 EDT 1993
I have used the following code to allocate and free memory in one of the
r.le programs:
pt = (int *)G_calloc(100, sizeof(int));
...
for (i=0; i<100; i++)
free(pt[i]);
free(pt);
This works fine on Sun systems with a version of Unix System V, but
failsproduces the compiler message "incompatible integer/pointer combination"
on Apollo machines with bsd4.3. I forgot to mention that the declaration
is "int *pt;" before the above code. This problem was found by Lars
Schylberg.
Lars was able to fix the problem on the Apollo by replacing free(pt[i])
with free(&pt[i]). However, when I do this on my Sun I quickly run out
of memory, indicating that the memory is not being freed correctly.
I am simply a beginning programmer and can't find anything in the usual
C books about this. Anyone know a universal method for freeing memory
that will work with System V and bsd?
Bill Baker
bakerwl at corral.uwyo.edu
Univ. of Wyoming, Laramie
307-766-3311
More information about the grass-dev
mailing list