Saturday, October 16, 2010

On Wasting Memory

I occasionally read about people suggesting use of suboptimal texture formats like GL_RGB so as to not "waste memory". That's an interesting concept, and it doesn't quite fit in with the defintiion of the word "waste". Let's look at a dictionary, shall we?

waste
1. to consume, spend, or employ uselessly or without adequate return; use to no avail or profit; squander: to waste money; to waste words.
2. to fail or neglect to use: to waste an opportunity.
3. to destroy or consume gradually; wear away: The waves waste the rock of the shore.
4. to wear down or reduce in bodily substance, health, or strength; emaciate; enfeeble: to be wasted by disease or hunger.
5. to destroy, devastate, or ruin: a country wasted by a long and futile war.
6. Slang . to kill or murder.
Right, some of those aren't really applicable here (no prizes for guessing which) but some offer an interesting and different perspective on the word "waste".

Let's take the example of 2 Quake engines. In one of them the programmer has frugally fine-tuned every single resource allocation and it only needs 8 MB of video RAM. In the other one the programmer has not been so meticulous and it needs 64 MB of video RAM. Which one is "wasting memory"? A lot of people would say the second one, but is it?

Back to the dictionary. Definition 1. Is the extra 56 MB being consumed, spent or employed uselessly? Or is it being used for something? Like faster (but larger) texture formats, vertex buffers or something else? Not so clear now, is it?

On to definition 2. This is where things turn totally upside down. On a typical low-end machine from a few years ago (with 128 MB of video RAM), the first engine is neglecting to use a total of 120 MB of video RAM, while the second is only neglecting to use 64 MB. By definition 2, the engine that only needs 8 MB is actually wasting almost twice as much video RAM as the one that needs 64 MB.

You see, video RAM is not one of those resources that needs to have every drop of it preciously conserved. It's there to be used, and if you're not using it, then it's lying idle. (In a funny twist on this, the programmer of the first engine has actually wasted time and energy - by definition 1 - in a lot of effort that was not actually needed!)

So by all means talk about "saving memory" where appropriate, and avoid needless use of it for sure, but everybody should reconsider what they mean by "waste" before using that word, because it might not mean what they think it does!

2 comments:

Anonymous said...

Most new machines have, what, at least 2GB of RAM in them now? My *laptop* has 8GB of RAM. Lets put it to use, people!

Great post, mh.

Nyarlathotep said...

That's quite insightful. However, I think one's definition of "waste" in this context is intimately tied to the stated goals of the project. MHQuake's goal is to take advantage of modern hardware using Direct3D 9; as no discrete DX9 cards were sold with less than 64 MB RAM, and they have a multitude of features available which can improve the experience of a game designed well before they existed, it makes sense to avail yourself of a huge amount of RAM. If some other engine designer wants his project to run comfortably on a 16 MB Matrox G400 or a Voodoo3, then he's free to do so as well. Designers shouldn't have to worry about fending off pot shots from people who can't think past their own narrow preconceptions. The source is open, and of all the complaints one could levy at the community, an insufficient number of Quake ports really isn't among them.