Thread: What's meaning of allocate memory at Run time

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    127

    What's meaning of allocate memory at Run time

    When we write a program, we build and compile it, then the program runs on the PC, which is called the run time.

    we say allocate memory at RUN time, This confused me a lot, What's meaning of allocate memory at Run time

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,920
    dynamic allocation
    See malloc and related functions.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2017
    Posts
    127
    Quote Originally Posted by stahta01 View Post
    dynamic allocation
    See malloc and related functions.

    Tim S.
    That I know malloc allocate memory at run time but again there is sentence " allocate memory at run time " That's not clear for me

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,920
    Do you know what it means to allocate memory at compile/build time?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,883
    It means that when your user opens your program the memory is not allocated yet.


    Another way of looking at it is a work project and getting funding for it (where the money represents memory in this analogy).

    At the start of a project I may be able say, "it will cost $1200", and that is great: I ask for that amount, get it approved, less paperwork, ect...

    However, there are certain things that I don't know how much it will cost (such as the cost to maintain a machine). To get around this I ask for the funds as I need it. This can be viewed as "dynamically allocated funds". This requires more paperwork, but it is more practical because we don't honestly know how much it will cost and we don't want to allocate all the funds to this one project when there are other projects going on at the same time.
    Fact - Beethoven wrote his first symphony in C

  6. #6
    Registered User
    Join Date
    Apr 2020
    Posts
    7
    Dynamic memory is allocated on the heap with the malloc() family of functions. In contrast, function calls push their local variables to the stack. Heap memory persists until you free it. You would allocate memory dynamically at runtime when you need to store more data than you initially anticipated.

  7. #7
    Registered User
    Join Date
    Apr 2020
    Posts
    11
    To illustrate the difference:

    Compile time allocation:

    static char fred[128];

    Run time equivalent:

    char * fred;
    fred = malloc(128);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2012, 04:28 AM
  2. Replies: 3
    Last Post: 07-02-2011, 05:20 AM
  3. whats the meaning of this allocate ?
    By the_contractor in forum C Programming
    Replies: 2
    Last Post: 01-25-2010, 11:58 AM
  4. Allocate memory inside allocated memory block?
    By Heidi_Nayak in forum C Programming
    Replies: 14
    Last Post: 04-15-2009, 04:19 PM
  5. when to allocate memory
    By SAMSAM in forum Windows Programming
    Replies: 3
    Last Post: 01-22-2003, 11:40 PM

Tags for this Thread