Jump to content


Code optimization/Game performance


9 replies to this topic

#1 Fukushousha

    New Member

  • Members
  • Pip
  • 6 posts

Posted 03 February 2007 - 11:21 PM

First of all , hello to everyone since this is my first post in these forums.I am making a 2D game strategy-like in C++ , using the SDL library.

Since this is the first game that is not 2D platform and is more complicated than pac-man (referring to my previous games in Java )...I am starting to experience rapid decrease in performance.I put an fps counter and it starts around 40 but as the game progresses falls at about 30.Also after a few compile & runs even after I quit my program my computer goes extremely slow , as if all its physical memory is taken.Even opening a folder at windows takes around 10 seconds
I know it must be memory leak.And as a new programmer to C++ I know that I am prone to not freeing memory used by pointers , but I specifically searched for that and saw that this was not the case.

So my question is , any tips for improving game performance by optimizing the code?Also .... what is a good fps to try to keep the game at?

On a sidenote: Great site , glad to have found another site with great info for game developing :) .

EDIT 2: Weird , I almost double posted the topic , it notified me of not being logged in , so I would post it again but saw that it got posted anyway.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 04 February 2007 - 01:11 AM

If the poor performance persists after your program terminates, then I doubt it is a memory issue. The OS will free all your memory when the program ends even if you don't free it yourself...unless your program is not really terminating but staying alive as a 'zombie' process. Use the Windows Task Manager (press Ctrl+Shift+Esc) and monitor the 'processes' tab, which will show your memory and CPU usage, and verify that your program really terminates. You might find that it is not your program at all but something entirely different causing the poor responsiveness.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Fukushousha

    New Member

  • Members
  • Pip
  • 6 posts

Posted 04 February 2007 - 07:58 AM

Yea that was my first thought , but it did not stay in the Task manager.Unless there is something wrong with DevC++.

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 04 February 2007 - 08:01 AM

Do you notice anything else in the task manager? Like an abnormal level of CPU usage after the program terminates, or a very large memory consumption from some program?

Another possibility is that it could be a hardware fault. Dying hard drives frequently cause slow responsiveness as the computer spends more time in disk swapping due to failed reads.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Fukushousha

    New Member

  • Members
  • Pip
  • 6 posts

Posted 04 February 2007 - 08:42 AM

Actually no ... and that is what seemed strange to me.It was using 15% of the memory , yet the whole situation is as described above.

#6 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 812 posts

Posted 04 February 2007 - 12:32 PM

I had some problems with DevCpp sometimes. The compiler wasn't shutting down after it was finished compiling, causing slowdown. Check your processes again?

#7 Fukushousha

    New Member

  • Members
  • Pip
  • 6 posts

Posted 04 February 2007 - 12:52 PM

Maybe that's it.I will recheck it when I get home , that's whereI got all the source.

#8 Cipher3D

    New Member

  • Members
  • Pip
  • 9 posts

Posted 04 February 2007 - 09:55 PM

it could be that you're not freeing SDL resources, etc. Perhaps you're opening a lot of files and neglecting to close the file handles? I know the OS *should* take care of these after you terminate the program, but you might as well do your homework and check that you have open/close, new/delete operations properly paired. Could you describe how you're managing resources a little bit more?

Cheers,
Cipher3D

#9 Fukushousha

    New Member

  • Members
  • Pip
  • 6 posts

Posted 05 February 2007 - 12:43 AM

WEll checked for it again but as I told you , I free all the memory and close all the files properly.Still this is strange. :/

#10 Fukushousha

    New Member

  • Members
  • Pip
  • 6 posts

Posted 05 February 2007 - 11:06 PM

I solved most of the problem , and posing it in here in case anyone has anything like that in the future.

The problem lied with DevC++ ... switched to codeblocks and now all is fine.I am not sure how exactly devC++ messed me up but it did :(





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users