question about memory shortage

Discussion in 'C Programming' started by Chang Byun, Oct 14, 2003.

  1. Chang Byun

    Chang Byun Guest

    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
     
    Chang Byun, Oct 14, 2003
    #1
    1. Advertising

  2. Chang Byun wrote:
    > 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).

    --
    Allin Cottrell
    Department of Economics
    Wake Forest University, NC
     
    Allin Cottrell, Oct 14, 2003
    #2
    1. Advertising

  3. Chang Byun <> wrote in message news:<bmfi1o$17om$>...
    > 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.

    --
    Devarshi Chatterjee
    http://yallara.cs.rmit.edu.au/~dchatter
     
    Devarshi Chatterjee, Oct 14, 2003
    #3
  4. Chang Byun

    Chang Byun Guest

    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

    Chang Byun wrote:
    > 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
    >
     
    Chang Byun, Oct 14, 2003
    #4
  5. Chang Byun

    Chang Byun Guest

    problem solved

    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

    Chang Byun wrote:
    > 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
    >
     
    Chang Byun, Oct 14, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mahesh Prasad
    Replies:
    1
    Views:
    712
    Tom Wells
    Feb 22, 2004
  2. Cy Huckaba
    Replies:
    1
    Views:
    1,153
    Xie Xiao
    Jun 26, 2003
  3. eglato
    Replies:
    117
    Views:
    2,349
    Tris Orendorff
    Jun 24, 2005
  4. Chang Byun

    memory shortage

    Chang Byun, Oct 14, 2003, in forum: C Programming
    Replies:
    1
    Views:
    324
    Ravi Uday
    Oct 14, 2003
  5. Chang Byun

    question about memory shortage

    Chang Byun, Oct 14, 2003, in forum: C Programming
    Replies:
    0
    Views:
    325
    Chang Byun
    Oct 14, 2003
Loading...

Share This Page