Cut down on memory usage
#1 Members - Reputation: 438
Posted 20 August 2011 - 01:58 PM
here is their info:
Operating System: Windows Vista Home Premium (6.0, Build 6002)
System Model: Toshiba Satellite Pro L300
Processor: Intel Celeron CPU - 550 @ 2.00GHz
Memory: 1014MB
DirectX: 11
Display: Mobile Intel 965 Express Chipset Family (250mb)
it is a quite simple game.
im using C++ and SDL, i have no knowledge of using the new type definition.
what could the problems be?
#3 Moderators - Reputation: 3974
Posted 20 August 2011 - 02:28 PM
Unless you are using OpenGL with SDL then chances are all your graphics operations are being done in software on the CPU which would be why the game is running slow.
#4 Members - Reputation: 438
Posted 20 August 2011 - 04:09 PM
#5 Members - Reputation: 416
Posted 20 August 2011 - 04:19 PM
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
#6 Members - Reputation: 530
Posted 20 August 2011 - 04:22 PM
#7 Moderators - Reputation: 5066
Posted 20 August 2011 - 04:24 PM
Lots. More than could be enumerated without more information. Answering Wooh's questions would be illuminating. Other questions to ask is how much I/O and page swaps the program is doing.what kind of mistakes are there to be made?
I recommend building a version of your game with a basic, built in profiler and logging. So, you might record number of time units spent updating, rendering, etc, etc. Append the values every few seconds to a file. By looking at the minimum and maximum values, the average value and the standard deviation, plus the duration of "spikes", you can get an accurate idea of what your program is spending its time doing. Consider also logging any event that should be rare or unusual, for example file access. You might be able to correlate the latency spikes with such events.
The simplest cause is just doing more work than the CPU/GPU/Disk can handle. For example, running your game at some ultra hi-res 1,000,000 x 1,000,000 pixels on your powerful development machine can cause problems for users with more modest computers.
Another common cause are memory leaks, which is allocating memory but not freeing it correctly once it you are finished using it.
Simple games are sometimes written so that each game object loads a file or set of files when it is created. Caching these images at load time, sharing them at runtime and freeing them during shutdown saves I/O time, CPU time and memory. For small games, you should be able to avoid touching the disk during runtime (except maybe at level transitions, etc).
No. In general, this would be worse.would it be better to use a new int* than just a int in a function?
#8 Members - Reputation: 313
Posted 20 August 2011 - 04:31 PM
SDL_SetVideoMode(width, height, 0, flags);Another common mistake is to not use SDL_DisplayFormat. Without seeing your code we can only guess.
#9 Members - Reputation: 438
Posted 20 August 2011 - 06:33 PM
http://www.mediafire.com/?9e549l4wjbbnp0g
the password is survivor.
please look and reply back with anything that might be causing this guy to have issues.
#10 Members - Reputation: 313
Posted 20 August 2011 - 07:15 PM
EDIT: To clarify: When you blit one surface to another surface they must have the same format. If they have different formats SDL_BlitSurface will automatically convert the source surface into a copy with the same format as the destination surface before blitting. This is slow and it happens every time. For this reason SDL_DisplayFormat is often used when loading surfaces to convert the surface into the same format as the screen surface. When you call SDL_Flip(screen), if screen has a different format than the `real screen settings` it will also have to convert here each time you call SDL_Flip. I guess your display is set to 32 bpp but what about your friend?
EDIT2: I also noticed your timing code is not working.
StartNum = SDL_GetTicks();
if ((SDL_GetTicks()-StartNum)<(1000/APP.FPS)){SDL_Delay((1000/APP.FPS)-(SDL_GetTicks()-StartNum));}If we assume all calls to SDL_GetTicks() returns the same number we can simplify the code to this if (0 < 1000/APP.FPS)
{
SDL_Delay(1000/APP.FPS);
}You are sleeping the same amount each frame so the game will run slower on a slow computer and faster on a faster computer.
#11 Members - Reputation: 438
Posted 20 August 2011 - 09:14 PM
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?
#12 Members - Reputation: 313
Posted 21 August 2011 - 05:36 AM
maybe something like this:Thanks for the second edit, i knew i messed up but never got around to fixing it... what should i do to fix it?
// 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;
}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.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?
See the SDL documentation for more information:
http://sdl.beuc.net/sdl.wiki/SDL_DisplayFormat
http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode
#13 Members - Reputation: 283
Posted 21 August 2011 - 09:16 AM
WARNING: I edit my posts constantly.
#15 Moderators - Reputation: 5066
Posted 21 August 2011 - 10:42 AM
It should be easily capable of running a SDL game.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.
#17 Members - Reputation: 283
Posted 21 August 2011 - 08:37 PM
It should be easily capable of running a SDL game.
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.
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.
WARNING: I edit my posts constantly.
#18 Moderators - Reputation: 5066
Posted 22 August 2011 - 02:41 AM
Yes, of course it is an opinion. Just as it is your opinion that the machine is "outdated"."Should" and "Will" are completely different terms and "should" declares the statement as an opinion.
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.
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.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.
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.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.
#19 Members - Reputation: 283
Posted 22 August 2011 - 03:49 AM
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...
WARNING: I edit my posts constantly.
#20 Moderators - Reputation: 5066
Posted 22 August 2011 - 04:15 AM
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.Doesn't matter if the computer is or is not outdated. This single line, is evidence that they cannot run it.
It really depends on the range of hardware tested. You're inferring an awful lot that should be stated explicitly before being relied upon.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 starting every second sentence with a question incredibly annoying? Yes.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.
Sounds like circular logic.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.
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.
That is exactly my point!Average 2D games will not exceed said computers system specs...
Emphasis added....but the op did say:
its actually not that simple when i think of it...
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.






