LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-16-2012, 10:31 PM   #1
suttiwit
Member
 
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:
Code:
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
+1

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, 07:22 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
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).
 
  


Reply


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 08:27 AM
how to free memory immediately after calling free in C programming golden_boy615 Programming 2 12-03-2011 07: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 07:05 AM
Application Virtual address space memory allocation - memory does not get free chamara82 Linux - General 4 01-01-2011 08:19 PM
[SOLVED] Memory leak: How risky not to free allocated memory. kaz2100 Linux - General 1 12-24-2008 12:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:30 AM.

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