Thread: c program to get RAM and write to text file

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    4

    c program to get RAM and write to text file

    Hi there,

    I'm brand new to C programming.

    I was wondering if somebody could demonstrate a program how you could get the available RAM on my computer and write it to a text file?

    Many thanks
    Stev

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    That would depend on your OS and Compiler.
    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.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    4
    Hi,

    I'm using a gcc compiler on a ubuntu OS.

    Thanks
    Stev

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Parse the contents of /proc/meminfo, and do what you need with it.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    What Elkvis said. The fields are listed in man 5 proc.

    Because the Linux kernel uses free memory for caching filesystem accesses, the amount of RAM available ("free") is roughly MemFree + Buffers + Cache.

    It does not mean a program can expect to be able to allocate that amount, as that is completely different policy, and can be controlled per user an so on; it also depends on whether or not overcommit (allow more than physical RAM available in allocations) is enabled. In other words, an application might be able to allocate more or less than that, depending on the OS configuration.

    The amount of "free" memory is rarely useful information to an user. In particular, most applications are snappier when a lot of memory is used in Cache, because then the application and library files, as well as the data files used, are cached in RAM. That way they're immediately available, and you don't need to wait for the files' contents to be read from disk. Because the latencies on human actions are shorter, the applications feel snappier.

    The only time you want to clean the cache (and there is a single-line command to do that) is when benchmarking I/O-sensitive applications.

    I have seen time and time again Windows users wanting to "free some RAM", desiring a higher MemFree amount, because they incorrectly assume that it makes applications snappier in sane operating systems. It does not. What Windows needs, is peculiar and weird, and is not portable to other systems in general.

    For users, MemFree is useful only as an indicator how much more RAM they have than they actually need. Cached is useful as an indicator to show how large your typical working set is. That's it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-18-2009, 01:17 PM
  2. Write to a Text File
    By slowcoder in forum C Programming
    Replies: 3
    Last Post: 08-14-2007, 07:52 AM
  3. write a file text
    By mickey0 in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2007, 03:36 AM
  4. is there a way to write the file names in a folder in a text file?
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-15-2002, 05:11 PM
  5. Write some text to a file
    By Unlimited4s in forum C++ Programming
    Replies: 7
    Last Post: 07-17-2002, 03:37 AM

Tags for this Thread