Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-16-2012, 11:31 PM   #1
Registered: Aug 2012
Location: Chiang Mai, Thailand
Distribution: Kubuntu 12.10 x86_64
Posts: 192
Blog Entries: 2

Rep: Reputation: 22
Display free and used memory on my C game.

Hi, I made a game on C. It has got debug mode.
Here is what the debug mode looks like:
Welcome to Press-LS 1.0 (With Debug Mode)
Created by: Suttiwit Sukpinit (milo).
Instructions: You must type 'ls' and press enter, do that repeatedly and as fast as possible without making mistakes!
              Here are some commands you are allowed to use in the game:
              hint          Shows what command you should type.
              exit          Exits the game and shows the result.
              peek          Peek at your score while in the game (Requires a peeky).
              rduc          Reduce Fails (Requires a Duck).
              fcon          Converts Fails to Pass and clear all fails to 0 (Requires a Falcon).
              clear         Clear the screen if it is messy.
              Typing 'ls' correctly will show '+1' on the screen and gives you 1 pass.
              Typing 'ls' incorrectly will show '-1' on the screen and gives you 1 fail.
              Have fun! :-)
$ ls

VAR_NAME/TYPE           ADDRESS              VALUE
PASS (INTEGER)           0x7fffd5578ca8       1
FAILS (INTEGER)          0x7fffd5578ca4       0
RAN (INTEGER)            0x7fffd5578ca0       0
PEEKY (INTEGER)          0x7fffd5578cbc       0
DUCK (INTEGER)           0x7fffd5578cb8       0
FALCON (INTEGER)         0x7fffd5578cb4       0
PEEKY_DOSE (INTEGER)     0x7fffd5578cb0       0
DIVB (INTEGER)           0x7fffd5578cac       2
UCMD (STRING)            0x7fffd5578aa0       ls
RCMD (STRING)            0x7fffd5578cc0       ls
Very cool, but, I would like to have the free & used memory in Kilobytes displayed.

What would be the code?
Old 10-18-2012, 08:22 AM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Originally Posted by suttiwit View Post
What would be the code?
Nice try, but I think I will leave that up to you implement.

As for where you can get the information you require, you can read the text file /proc/meminfo. I believe the first two lines of the file are what you need (MemTotal and MemFree).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Virtual Memory limit exhausted at 1TB? malloc/mmap failures even with free memory mfkraft Linux - Server 2 09-16-2012 09:27 AM
how to free memory immediately after calling free in C programming golden_boy615 Programming 2 12-03-2011 08:09 AM
looking for free database that has low memory usage and innodb and memory like engin golden_boy615 Linux - Software 8 05-08-2011 08:05 AM
Application Virtual address space memory allocation - memory does not get free chamara82 Linux - General 4 01-01-2011 09:19 PM
[SOLVED] Memory leak: How risky not to free allocated memory. kaz2100 Linux - General 1 12-24-2008 01:00 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration