Jump to content
  • Advertisement
Sign in to follow this  
BennettSteele

Cut down on memory usage

This topic is 2470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:

[font=arial, sans-serif][size=2]
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?[/font]

Share this post


Link to post
Share on other sites
Advertisement
There are many possible causes..
How much memory is the game using?
How is the cpu usage when the game runs?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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. . . .

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

what kind of mistakes are there to be made?
[/quote]
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?
[/quote]
No. In general, this would be worse.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!