question about memory shortage

C

Chang Byun

I have question about memory allocation.

I have a trouble when I run a C program.
My C program has several big double pointer(** var) variables to
structure data like 4 by 5000000.
It is supposed to calculate those varibles with different parameters
repeatedly with same size of variables.
When it is running, the first several run is fine
But it uses more and more memory, is used up all the main memory
and swap memory and is stop.
I am pretty sure that I free every variable for each run using free().

My questions are,

1. if the process needs more memory space even though every
variables are released with free().
2. How can I check if there is memory leak?
3. Would it be better if big variables breaks down to smaller size
variables.

Any suggestions and helps would be very appreciated.

Thanks,

Chang Byun
 
A

Allin Cottrell

Chang said:
I have question about memory allocation.

I have a trouble when I run a C program.
My C program has several big double pointer(** var) variables to
structure data like 4 by 5000000.

That's 20,000,000 per shot. If the vars are (say) doubles, it's
likely to be 160 Megabytes a shot. Divide this into the target
machine's RAM to see how many such arrays you can expect to get
away with. (On my computer you'd be lucky to create two such
arrays, given the RAM used up by other programs.)
It is supposed to calculate those varibles with different parameters
repeatedly with same size of variables.
When it is running, the first several run is fine
But it uses more and more memory, is used up all the main memory
and swap memory and is stop.
I am pretty sure that I free every variable for each run using free().

My questions are,

1. if the process needs more memory space even though every
variables are released with free().

If you're really freeing memory, that memory should be made available
for subsequent malloc() calls by your program, if the C implementation
is any good.
2. How can I check if there is memory leak?

With a memory checker such as valgrind,

http://developer.kde.org/~sewardj/

(this one is for x86-linux, which may or may not suit your purposes).
 
D

Devarshi Chatterjee

Chang Byun said:
I have question about memory allocation.

I have a trouble when I run a C program.
My C program has several big double pointer(** var) variables to
structure data like 4 by 5000000.
It is supposed to calculate those varibles with different parameters
repeatedly with same size of variables.
When it is running, the first several run is fine
But it uses more and more memory, is used up all the main memory
and swap memory and is stop.
I am pretty sure that I free every variable for each run using free().

My questions are,

1. if the process needs more memory space even though every
variables are released with free().
2. How can I check if there is memory leak?
3. Would it be better if big variables breaks down to smaller size
variables.

Without having a chance to look at your code, I'd say
you probably aren't free()ing the memory properly.

To check for memory leaks, you could use bcheck (and inherently
dbx) though I *think* their use is restricted to Solaris.
Any suggestions and helps would be very appreciated.

Thanks,

Chang Byun


HTH.
 
C

Chang Byun

Thanks a lot guys for your kind reply and help.

I found my mistake.
I missed to free one temporary variable in a subroutine.

Thanks again.

Chang
 
C

Chang Byun

Thanks a lot guys for your kind reply and help.

I found my mistake.
I missed to free one temporary variable in a subroutine.

Thanks again.

Chang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top