How memory function free() knows how much memory to free.

Discussion in 'C Programming' started by Panduranga Chary, Dec 27, 2007.

  1. Hi,

    How does the memory management function 'free()' frees the memory
    pointed by a pointer variable at run time. how does it know the size.
    if there is way when free() can do, then why can't we do it
    externally?.


    Thanks
    Panduranga Chary
     
    Panduranga Chary, Dec 27, 2007
    #1
    1. Advertising

  2. Panduranga Chary

    MisterE Guest


    > Hi,
    >
    > How does the memory management function 'free()' frees the memory
    > pointed by a pointer variable at run time. how does it know the size.
    > if there is way when free() can do, then why can't we do it
    > externally?.


    When you malloc memory, the size of the allocated block is stored somewhere.
    What do you mean by externally?
     
    MisterE, Dec 27, 2007
    #2
    1. Advertising

  3. Panduranga Chary <> writes:
    > How does the memory management function 'free()' frees the memory
    > pointed by a pointer variable at run time. how does it know the size.
    > if there is way when free() can do, then why can't we do it
    > externally?.


    The comp.lang.c FAQ is at <http://www.c-faq.com/>.
    You've just asked question 7.26.

    --
    Keith Thompson (The_Other_Keith) <>
    [...]
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 27, 2007
    #3
    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. sincethe2003
    Replies:
    6
    Views:
    2,506
    sincethe2003
    Jul 19, 2004
  2. Jim H

    letting free() know how much to free...?

    Jim H, Mar 4, 2004, in forum: C Programming
    Replies:
    9
    Views:
    399
    Malcolm
    Mar 6, 2004
  3. how much does free free?

    , Apr 28, 2007, in forum: C Programming
    Replies:
    13
    Views:
    533
    Giorgos Keramidas
    May 2, 2007
  4. cpp4ever
    Replies:
    3
    Views:
    398
    Francesco
    Sep 8, 2009
  5. Raymond Schanks
    Replies:
    0
    Views:
    591
    Raymond Schanks
    Apr 11, 2010
Loading...

Share This Page