r3dux.org

A number-pimping side project from the valleys in *NEW* upside-down flavour.

  • Home
  • ABOUT
  • OLD SITE
  • SEARCH
  • FEEDBACK

Why is Linux using all my RAM?

r3dux | January 27, 2012

My Linux-running laptop seemed to be a little bit sluggish, so I had a look at the amount of free RAM available – and did a double take:

Linux free RAM confusion

A few apps eating an entire 4GB? Say it ain't so!

This is on a 4GB machine with a web browser (6 tabs) open, email client, code::blocks IDE and totem to play some music. How can that devour my entire 4GB?

Answer: It can’t. Or at least it’s not! The Linux kernel is in fact using free RAM as a disk cache to keep your most often used data in memory and thus speed up the system. As soon as that RAM is actually needed for applications, then it’s instantly made available. This is in theory like the Windows Superfetch service (which is the first thing I disable on any Windows machine I’m forced to co-exist with), only the Linux version actually works well without perpetually thrashing the pants off the hard drive.

What’s really happening is this:

Linux free RAM in reality

It ain't so =D

For the exact workings, please see the excellent (and indeed excellently named) site “Help! Linux ate my RAM!” – http://www.linuxatemyram.com/.

Bit of a PEBKAC moment, there ;-)

Comments
No Comments »
Categories
Linux, Tech
Tags
Cache, Free, RAM, Superfetch
Comments rss Comments rss
Trackback Trackback

Happy Australia Day!

r3dux | January 26, 2012

Australia Day 2012

You can read about the history of Australia Day here, if you’re interested. Or just throw another shrimp on the barbie and be thankful for the day off =D

Comments
No Comments »
Categories
Life
Tags
Aussie, Australia, Australia Day, holiday
Comments rss Comments rss
Trackback Trackback

NBA 2K12 is…

r3dux | January 24, 2012
NBA 2K12 is...

Not even rigged - try it for yourself...

Game is teeth-gnashingly hard against the AI on standard “Pro” difficulty. It’s upsetting.

Comments
2 Comments »
Categories
Gaming, Humour
Tags
Basketball, NBA, NBA 2K12, Too damn hard
Comments rss Comments rss
Trackback Trackback

Dante Bucci – Fanfare

r3dux | January 23, 2012

I’d never even heard of Hangs / Hang drums before today – check them out! Amazing!

YouTube Preview Image

Like playing a flying saucer – really, really well! =D

Comments
No Comments »
Categories
Music
Tags
Dante Bucci, Fanfare, Hang Drums, Hangs, Instrument, Mad Skillz
Comments rss Comments rss
Trackback Trackback

How-to: Overload the C++ function operator()

r3dux | January 20, 2012

I’m working my way through the first few chapters of James Reinders’ Intel Threading Building Blocks book, and its a little bit hard going. As much as I’m enjoying the mental exercise of thinking in parallel, when it actually comes to the coding they use a lot of function operator (i.e. operator()) overloading, and I’m not so familiar with it. As much as I’ve overloaded operators before so you could, for example, add two Fruit objects together and get their weight, or multiply an Employee->monthlySalary by 12 to get their yearly wage, I’d never overloaded the function operator itself, so wasn’t sure what was really going on in the code.

To fix this, I’ve knocked together a super-simple example to show how it works:

#include <iostream>
using std::cout;
using std::endl;
 
class Foo
{
	public:
		// Property
		int number;
 
		// Constructor
		Foo() : number(0)
		{
			cout << "Constructing an object of type Foo..." << endl;
		}
 
		// First overloaded function operator, i.e. we're overloading the operator ()
		void operator()()
		{
			cout << "From our first overloaded () operator, I get the number: " << number << endl;
		}
 
		// Second overloaded function operator
		void operator()(Foo &first, Foo &second)
		{
			if (first.number > second.number)
			{
				cout << "The first number property is greater than the second number property." << endl;
			}
			else
			{
				cout << "The first number property is less than or equal to the second number property." << endl;
			}
		}
};
 
void doNothing(Foo tempFoo)
{
	cout << "I'm not using the overloaded () operator here." << endl;
}
 
int main()
{
	// Create our first test object
	Foo firstObject;
 
	// Make sure it's initialised with the default value specified in the constructor
	cout << "From main, number is: " << firstObject.number << endl;
 
	// Call the doNothing function on our Foo object - doesn't do a lot!
	doNothing(firstObject);
 
	// Anonymous object creation (i.e. invokes the constructor - but we don't keep a named object)
	Foo();
 
	// ***THIS*** is where the overloaded function operator comes in!
	firstObject();
 
	// Create a second test object and specify a value
	Foo secondObject;
	secondObject.number = 5;
 
	// Run our first overloaded function operator again on a different object
	secondObject();
 
	// Run our second overloaded function operator on the first object
	firstObject(firstObject, secondObject);
 
	// Run our second overloaded () operator (function operator) again, but on diff object
	// It doesn't matter which object we run it on - behviour is only dependant on the order
	// in which we supply the object parameters in this case!
	secondObject(firstObject, secondObject);
 
	// Finally, just to prove we can trigger the second path in the 2nd overloaded function operator...
	secondObject(secondObject, firstObject);
 
	return 0;
}

Which gives the output:

Constructing an object of type Foo...
From main, number is: 0
I'm not using the overloaded () operator here.
Constructing an object of type Foo...
From overloaded () operator, I got the number: 0
Constructing an object of type Foo...
From overloaded () operator, I got the number: 5
The first number property is less than or equal to the second number property.
The first number property is less than or equal to the second number property.
The first number property is greater than the second number property.

So, that’s how it works. Straight forward enough.

Another example, taken from the Function object wikipedia page:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iterator>
#include <algorithm>
 
class countfrom {
	private:
		int &count;
	public:
	  countfrom(int &n) : count(n) {}
	  int operator()() { return count++; }
};
 
int main() {
	int state(10);
	std::generate_n(std::ostream_iterator<int>(std::cout, "\n"), 11, countfrom(state));
	return 0;
}

Counting from 10 to 20 has never been funner =D

Comments
No Comments »
Categories
Coding
Tags
C++, Coding, Function, Function Operator, Operator, Overloading
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Translate

Categories

Archives

Tags

3D ActionScript ActionScript 3.0 Adobe AI Ballarat Bash C++ Convert CS4 DVD Effect Film Flash GLSL Gnome Hack How-To install Jaunty Java Kinect Linkage Linux Mash-Up Microsoft Motion OpenGL Particle Photoshop Problem PS3 Remix Remove Retro script Slides Sound Systems Ubuntu Video VirtualBox Wii Windows XBox

Gamercard

OpenR3dux

Misc.

Flattr this

RSS Feed

r3dux twitter feed



“Taming the lion tamers”

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox