Thread: to find the heap size

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    1

    to find the heap size

    Hai all,

    I have one question in C. That is..
    How will you write a routine in C to find the heap size?
    if anyone knows the answer, pls post & clear my doubt.

    Thanks.

    -Vijay

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well, you either keep a static count of your nodes as you create and delete them and just return that to the program or you just have to iterate through the whole thing counting the non null nodes. And of course if you mean memory size, you just simply count up the number of nodes and multiply by sizeof(*node).

    Who knows, maybe there is some other magic routine I'm not thinking of right now. As far as I can see, those are your best bets.
    Sent from my iPadŽ

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > How will you write a routine in C to find the heap size?
    Read the manual pages and documentation which come with your compiler.
    There's no standard way to know this information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    If you're using linux then read up on the sbrk() function. You can record the return value once when your program starts and then compare that value with sbrk()'s current return value every time you want to query.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I always do this. I can't believe how stupid I am, I never learn. I see the word heap and I think of the data structure. Of course they're talking about runtime memory though.

    Someone slap me, I deserve it.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 06:14 PM
  2. char problem
    By eXistenZ in forum Windows Programming
    Replies: 36
    Last Post: 02-21-2005, 06:32 AM
  3. Replies: 11
    Last Post: 03-25-2003, 05:13 PM
  4. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 05:03 AM
  5. How to find file size?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 08-30-2001, 02:34 PM