Cut down on memory usage

Started by
23 comments, last by ApochPiQ 12 years, 8 months ago
Thanks for the second edit, i knew i messed up but never got around to fixing it... what should i do to fix it?

so what would it look like to do this?

would i need to change (when done with applying surfaces) create a new surface to flip with the correct BitsPerPixel?
if not, would i need to upload each image then convert each image?
Advertisement
Thanks for the second edit, i knew i messed up but never got around to fixing it... what should i do to fix it?

maybe something like this:// somewhere outside the loop you need to initialize nextFrameTime
Uint32 nextFrameTime = SDL_GetTicks();

...

// in the loop
Uint32 currentTime = SDL_GetTicks();
if (nextFrameTime > currentTime)
{
SDL_Delay(nextFrameTime - currentTime);
nextFrameTime += FRAME_TIME; // FRAME_TIME is defined as 1000/APP.FPS
}
else
{
// This else part is not strictly necessary but it
// makes so that if the game got behind schedule it
// will not speed up to catch up for lost time.
// Maybe you want to handle this differently
nextFrameTime = currentTime + FRAME_TIME;
}


would i need to change (when done with applying surfaces) create a new surface to flip with the correct BitsPerPixel?
if not, would i need to upload each image then convert each image?

You set the format of the screen surface when you call SDL_SetVideoMode. This should never have to be changed. As I said earlier, if you pass 0 as the bpp to SDL_SetVideoMode it will automatically pick the best format. You also want to have the same format on all the other surfaces. By using SDL_DisplayFormat you can convert the surfaces into the screen format. Do this right after you have loaded a surface and you will not have to do it again. Do this for all surfaces (except the screen surface)! If the surface have an alpha channel use SDL_DisplayFormatAlpha instead of SDL_DisplayFormat.

See the SDL documentation for more information:
http://sdl.beuc.net/sdl.wiki/SDL_DisplayFormat
http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode
Their computer stats are quite dated. 1gb or ram, on board video(shared ram with system) and a Celeron 550. And then Vista installed on it to boot. Sounds like a netbook, and a very old one at that. 1gb of ram? I wouldn't expect they would be able to run anything, after vista is loaded, effectively even assuming a fresh install and a fully optimized OS.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.

Thanks alot. :)

I had no clue what the meaning of their computer stats were, so i just decided there was something wrong with my code. But thanks again, this was very helpful! :P

Their computer stats are quite dated. 1gb or ram, on board video(shared ram with system) and a Celeron 550. And then Vista installed on it to boot. Sounds like a netbook, and a very old one at that. 1gb of ram? I wouldn't expect they would be able to run anything, after vista is loaded, effectively even assuming a fresh install and a fully optimized OS.

It should be easily capable of running a SDL game.
Well my SDL game should have been made with OpenGL, its actually not that simple when i think of it...

[quote name='0Circle0' timestamp='1313939816' post='4851916']
Their computer stats are quite dated. 1gb or ram, on board video(shared ram with system) and a Celeron 550. And then Vista installed on it to boot. Sounds like a netbook, and a very old one at that. 1gb of ram? I wouldn't expect they would be able to run anything, after vista is loaded, effectively even assuming a fresh install and a fully optimized OS.

It should be easily capable of running a SDL game.
[/quote]

They keyword is "should", however if everyone else who uses the program runs it fine and then it is tested against a system with very limited resources and performs slowly then I would have to say the system is dated or unmaintained.

"Should" is a relative term, which implies that on new hardware, fresh vista install, and fully updated drivers as well as optimized OS then sure the Celeron 550 and 1GB of ram "should" run SDL games easily; however this hardware isn't new, the OS isn't new, and I am willing to bet the OS isn't frequently re-installed(or maintained) to keep it running as fast as possible, as the typical computer user never even re-installs(or even knows how to maintain a computer) any OS when their computer gets slow, they just assume their computer is just getting old and accepts the sluggish behavior.

"Should" and "Will" are completely different terms and "should" declares the statement as an opinion. Opinions(as the word "Should" implies) on if a specified hardware can or cannot run a specified application needs to be kept to real world testing rather than a guess with out any testing. My netbook with 2GB of ram and a much faster N260(Dual Core) will bog down against a high resource SDL or Allegro at times, and the netbook is frequently kept in prime condition and well maintained.

You're talking about a Celeron 550 (Single Core Processor released in late '06) with 1GB system ram that is shared with the video(which can take anywhere from 32MB-128 MB (Mine takes 128 as I use the same integrated video) depending on driver support), and then make the assumption that the said system with minimum system requirement for just running the OS (Windows Vista in this case) will then be able to effectively run anything else. This just isn't the case, as the test showed.

Is that to say there isn't any problems with the code, no. There may be many problems; however there may be none. No room for opinionated responses that completely contradict a real world test that was conducted against the program the OP mentioned to the hardware they also mentioned.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.


"Should" and "Will" are completely different terms and "should" declares the statement as an opinion.
[/quote]
Yes, of course it is an opinion. Just as it is your opinion that the machine is "outdated".

Maybe I'm just old fashioned, but that machine would have been considered extremely high end during the heyday of 2D gaming. I find it hard to think of a reasonable 2D game that should cause such a machine a significant burden.

The OP's link seems to be broken, so I cannot gauge how intensive the game might be. Maybe they're making Plasma Pong II, or something similar that would cause trouble for such a machine, I don't know. Given the OP's posting history however, this is unlikely to be the case. What is far more likely is that they are making some minor mistake which is costing them dearly on a much slower machine.


My netbook with 2GB of ram and a much faster N260(Dual Core) will bog down against a high resource SDL or Allegro at times, and the netbook is frequently kept in prime condition and well maintained.
[/quote]
This is ridiculous. Are you seriously suggesting you need such high specifications to run 2D games? I don't know what your definition of "high resource" is, but it seems to me it must be insane if it requires such power to run.


No room for opinionated responses that completely contradict a real world test that was conducted against the program the OP mentioned to the hardware they also mentioned.
[/quote]
I stand by my answer (again: unless the OP is writing a very unusual SDL game). I believe the OP is doing something incorrectly if their game doesn't work on such hardware.

on my computer it runs fine, its just that one person who has problems.


Doesn't matter if the computer is or is not outdated. This single line, is evidence that they cannot run it. By the usage of "just" which indicates more than one person was involved in testing should bring the conclusion that their hardware is not capable of running the program. Also indicated by "just" is that others are not having the same problem.

Is the computer outdated by standards of today? Yes(Which makes my statement not an opinion, but rather a observation of the standards of today). Is it outdated in the standards of running a 2D game made with basic SDL? No. Could the computer have other problems that would interrupt the games ability to effectively run? Possible, but inconclusive as no relevant data can be ascertained about the said computer. Does the game run fine for every other person who tried to run it? Yes.

Should the OP have kept the password the same on the source so that one of us could possibly look through the code instead of having 2 people speculate on what could be the cause instead of actually finding the real cause? Yes. Will they allow the code to be looked over again? Maybe. Is this discussion now pointless without further data on the subject? Yes.

Btw, the OP may very well indeed be doing something wrong. I'll concede to that; however there may be more to it.

High Resource can be defined as an excessive or large amount of memory being used by an application that exceeds the standard.
Standard can be defined the average expected usage of a given program.

Average 2D games will not exceed said computers system specs, but the op did say:

its actually not that simple when i think of it...

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.


Doesn't matter if the computer is or is not outdated. This single line, is evidence that they cannot run it.
[/quote]
Of course the hardware isn't capable of running the current implementation of application! My speculation is that the hardware should be capable - i.e. the application is doing something wrong.


By the usage of "just" which indicates more than one person was involved in testing should bring the conclusion that their hardware is not capable of running the program. Also indicated by "just" is that others are not having the same problem.
[/quote]
It really depends on the range of hardware tested. You're inferring an awful lot that should be stated explicitly before being relied upon.


Is the computer outdated by standards of today? Yes(Which makes my statement not an opinion, but rather a observation of the standards of today). Is it outdated in the standards of running a 2D game made with basic SDL? No. Could the computer have other problems that would interrupt the games ability to effectively run? Possible, but inconclusive as no relevant data can be ascertained about the said computer. Does the game run fine for every other person who tried to run it? Yes.

Should the OP have kept the password the same on the source so that one of us could possibly look through the code instead of having 2 people speculate on what could be the cause instead of actually finding the real cause? Yes. Will they allow the code to be looked over again? Maybe. Is this discussion now pointless without further data on the subject? Yes.
[/quote]
Is starting every second sentence with a question incredibly annoying? Yes. :P


High Resource can be defined as an excessive or large amount of memory being used by an application that exceeds the standard.
Standard can be defined the average expected usage of a given program.
[/quote]
Sounds like circular logic.

This aside, I cannot think of any reasonable definition of a "standard" 2D SDL game that requires 1GB of RAM and whatever a N260 is - a dual core processor means probably exceeds 1GHZ at least. Just because there might exist games that tax such a system, doesn't mean anything. They could be written poorly.


Average 2D games will not exceed said computers system specs...
[/quote]
That is exactly my point!


...but the op did say:

its actually not that simple when i think of it...
[/quote]
[/quote]
Emphasis added.

He said it was not simple. Not simple doesn't mean complex, it doesn't even mean his game is above average in terms of its resource demands.

This topic is closed to new replies.

Advertisement