Memory management in a program?

Okay, let's just say I created a very large console application.... Okay, it's a dungeon crawler, and before you spit on the ground before me, I realize the problems with games in the console. It was just something I really wanted to wrap up from a while back. Anyways, like I was saying, the program is quite large, and uses a whole lot of variables. I'm guessing this is what is causing the huge problem of the program sucking up all of my RAM? The unholy number is a whopping 129,000 K. That may not be 'whopping' to some other types of programs, but it sure is a lot to me in the aspects of something in a console, And it really starts to lag it down. So I was just wondering, how do I reduce the usage? Better yet, what exactly causes it? Like I said, I thought it was the variables and structures I have.
Don't use lots of globals.
Split functions up so you don't have a huge amount of variables "active" at once.
Make sure you aren't leaking memory somewhere.
On memory leaking, would it help for me to use 'new' and 'delete' frequently?
[misuse of] new and delete is what causes memory leaking.

If you want to avoid memory leaks, minimize the use of them.
Wait, I never use them though. So are my only other ways of reducing memory what Firedraco said?
Well a memory leak causes your program to consume more and more memory over time. If your program stays put at 129000K and doesn't grow, then you probably don't have leaks.

The only way to use less memory would be to... well... use less memory. Fewer variables, smaller buffers, etc.

So yeah, pretty much just what firedraco said. Globals hurt overall memory usage because they are "always there", even when you're not really using them.
Okay, it was a horribly stupid reason. I can't believe it didn't hit me earlier. I had a wave file start playing when you launch it, and it was around 140 MB in size. Commenting that out dropped it 128,000 K. I guess I know now the problems with playing full wave songs. Good grief.
Console game - 128 MB. Ok :)

You can use memory pools to decrease fragmentation (and it will improve the performance of allocation and may help diagnostics too). You can even use object pools. I don't know what you have going on there.

You can use data sharing (lightweight pattern). Say, you have many monsters with many different permanent characteristics (not states). Try to put the common characteristics of a certain class of monsters in a shared object or smth. It may decrease the performance though.

Try to use iterative solutions if you have deep recursions that can be collapsed into iteration.

Regards
Topic archived. No new replies allowed.