by Robert on June 28th, 2009

Robert

Question

Help answer this question below.

How can I find out, through a C prog, how much memory is available?

  • Like
  • Report

Answers. 3 helpful answers below.

  • by vittau on July 15th, 2009

    vittau

    You can make a for loop that will try to malloc an increasingly larger chunk of memory (and then free), and when it fails, this is how much memory you have.
    There surely is a better (and faster) way, but this is the only way I know...

    Oh and this method will count the virtual memory also...

    • Like
    • Report

    No comments. Post one | Permalink

  • by POP Fan on November 18th, 2009

    POP Fan

    You could try making a pointer and starting it at a position, say 0x0100, the starting point for .COM applications. You could continually increment this pointer, incrementing a counter variable for each location that the program is allowed to access. I'm not sure exactly how well this would work though, you'd likely crash the program trying to access a memory location outside of the correct segment, but the other two answers covered the best options.

    I think there was a function to find the number of bytes of free memory a computer has, but I don't remember it. It might be part of the Windows API.

    No comments. Post one | Permalink

  • by yeroco on July 22nd, 2009

    yeroco

    If you are on linux, you can read and parse /proc/meminfo.

    No comments. Post one | Permalink

Want to attach an image to your answer? Click here.

Did this answer your question? If not, then ask a new question or create a poll.

You're reading How can I find out, through a C prog, how much memory is available?

Follow us on Facebook!

Related Ads

ANSWERBAG BUZZ

Meena lagna
Find out how much memory available c program
Find out memory in ram using c program
Get how much memory is availble in c
Find out how much memory is available using c