Jump to content

  • Log In with Google      Sign In   
  • Create Account


Cut down on memory usage


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#1 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 20 August 2011 - 01:58 PM

Im making a game, and works perfect for me, but when i let someone try it, they said it was too laggy and such.
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?


Sponsor:

#2 Wooh   Members   -  Reputation: 608

Like
0Likes
Like

Posted 20 August 2011 - 02:15 PM

There are many possible causes..
How much memory is the game using?
How is the cpu usage when the game runs?

#3 phantom   Moderators   -  Reputation: 7039

Like
0Likes
Like

Posted 20 August 2011 - 02:28 PM

Unless you are doing something horrible horribly wrong then memory isn't going to be the problem.

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 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 20 August 2011 - 04:09 PM

on my computer it runs fine, its just that one person who has problems. i am using SDL, but not with openGL, and i could be making some mistakes. what kind of mistakes are there to be made? would it be better to use a new int* than just a int in a function?

#5 smasherprog   Members   -  Reputation: 432

Like
0Likes
Like

Posted 20 August 2011 - 04:19 PM

You are asking questions that cannot be answered at all. You have to identify exactly what the problem is. So far you say it is slow, that doesnt mean anything. It could be so many different potential problems, it wont help to guess. You must identify what is slow. Is the hardware underpowered. Is your code written poorly. Their computer could have a virus scanner installed that really sucks. Who knows. . . .
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

#6 fractor   Members   -  Reputation: 795

Like
0Likes
Like

Posted 20 August 2011 - 04:22 PM

If your game is laggy on someone else's computer, maybe memory usage is not the problem. You are loosing speed somewhere. You should identify where this happens (usually in the update or render methods). Maybe you're doing things like loading textures every frame. You can use a profiler to see where you are loosing speed.

#7 rip-off   Moderators   -  Reputation: 8110

Like
0Likes
Like

Posted 20 August 2011 - 04:24 PM

what kind of mistakes are there to be made?

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.

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).

would it be better to use a new int* than just a int in a function?

No. In general, this would be worse.

#8 Wooh   Members   -  Reputation: 608

Like
0Likes
Like

Posted 20 August 2011 - 04:31 PM

One problem I have seen other people do is when calling SDL_SetVideoMode. If you use a bits per pixel (bpp) argument that is different from the native display bpp it will have to make slow conversions each time you call SDL_Flip (or similar). Best is to pass 0 because that will pick the best for you.
SDL_SetVideoMode(width, height, 0, flags);
Another common mistake is to not use SDL_DisplayFormat. Without seeing your code we can only guess.

#9 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 20 August 2011 - 06:33 PM

here is all the source, i trust no one will try to steal my work. Posted Image

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. Posted Image

#10 Wooh   Members   -  Reputation: 608

Like
0Likes
Like

Posted 20 August 2011 - 07:15 PM

You assume bpp is 32 and you never call SDL_DisplayFormat, as I thought..

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 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 20 August 2011 - 09:14 PM

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?

#12 Wooh   Members   -  Reputation: 608

Like
0Likes
Like

Posted 21 August 2011 - 05:36 AM

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

#13 0Circle0   Members   -  Reputation: 342

Like
0Likes
Like

Posted 21 August 2011 - 09:16 AM

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.


#14 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 21 August 2011 - 10:13 AM

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

#15 rip-off   Moderators   -  Reputation: 8110

Like
0Likes
Like

Posted 21 August 2011 - 10:42 AM

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.

#16 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 21 August 2011 - 12:20 PM

Well my SDL game should have been made with OpenGL, its actually not that simple when i think of it...

#17 0Circle0   Members   -  Reputation: 342

Like
0Likes
Like

Posted 21 August 2011 - 08:37 PM


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.


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.


#18 rip-off   Moderators   -  Reputation: 8110

Like
0Likes
Like

Posted 22 August 2011 - 02:41 AM

"Should" and "Will" are completely different terms and "should" declares the statement as an opinion.

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.

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.

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.

#19 0Circle0   Members   -  Reputation: 342

Like
0Likes
Like

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...


Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.


#20 rip-off   Moderators   -  Reputation: 8110

Like
1Likes
Like

Posted 22 August 2011 - 04:15 AM

Doesn't matter if the computer is or is not outdated. This single line, is evidence that they cannot run it.

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.

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.

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.

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...

That is exactly my point!

...but the op did say:


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

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS