5 Replies - 693 Views - Last Post: 17 August 2012 - 06:10 PM Rate Topic: -----

#1 fatalpriapism  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 39
  • Joined: 17-August 12

Saving data to database

Posted 17 August 2012 - 03:52 AM

Ok, so I'm not a programmer by any means at this point, I'm still learning C++. I have been working on a simulation game project with a friend, and we have run into a couple issues we are trying to resolve.

The main one that I'm not really sure about how to address is this:

The game is written entirely in C++, with data in XML files. It is a memory hog and quickly eats up most of the available system memory, slowing the game to a near halt. I suggested the idea of using databases for some game data to free up system memory. That said, neither of us having any real experience with SQL.

So the question is...how would I go about integrating databases to increase game performance and decrease the overall draw on system resources?

Is This A Good Question/Topic? 0
  • +

Replies To: Saving data to database

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: Saving data to database

Posted 17 August 2012 - 05:29 AM

I guess a big question is what are you saving in these XML files and is it really required?
Was This Post Helpful? 0
  • +
  • -

#3 BBeck  Icon User is online

  • Here to help.
  • member icon


Reputation: 581
  • View blog
  • Posts: 1,290
  • Joined: 24-April 12

Re: Saving data to database

Posted 17 August 2012 - 06:34 AM

I agree with StayCrisp.

The first step is to look for waste and cut out the waste. Do you have textures that are larger than they need to be? Overlapping vertices? Are you using double words when you could have used bytes?

And if it's your XML files that are pegging the memory, you're either running on a 386 or your XML files are suspiciously large. I would assume that those XML files are loaded into appropriate datatypes in memory, rather than loaded into memory as XML.

Regardless, a database is probably not the answer. If the database is on the same computer, it's likely to make your memory problems worse, because it will increase the memory usage just having the database.

Now the database could (and maybe should) be on another box and then it doesn't contribute to memory problems on the client. Then you're going over to a more client-server model. But you will also have network latency problems, because it not only takes time for the database to find the data, but you are limited to network speeds, which tend to be a lot slower than pulling data off the local harddrive.

On the other hand, what databases are really good at is finding a needle of needed data in a mountain of data. So, really, the problem that the database solves is when you have to go sorting through massive amounts of data to find a few pieces of data. Then the database can just send over those few pieces of data and it's fast because it's not much data. Databases basically don't work at all if you keep asking them to send over the entire mountain of data to be processed locally.

If you do decide to use a database, you have to decide which one to use. Will you use Oracle, MySql, SQL Server, or something else. They are all very different. You said SQL, and in my world, that means SQL Server. For SQL Server, there are several technologies for accessing a database. ODBC is the oldest and probably the easiest to code (although I haven't looked at how to program databases in C++ in several years - it's a WHOLE lot easier to program for them in .Net (C#)). There's also ADO and OLE DB. And you may be able to use SQL Native Client for C++ also. Last time I looked, all of these were pretty difficult to learn in C++ (not too bad in C# or VB though).

Anyway, before you go down that route, think about what kind of data it is that you are storing. Think about how you can cut waste. And look at why the data is in memory and what needs to be in memory at any given point. You probably just need better memory management in the application than you need a database.

Maybe you should give us more specifics as to exactly what's eating up all the memory? And maybe we could offer some suggestions on how to better manage it.

This post has been edited by BBeck: 17 August 2012 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 fatalpriapism  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 39
  • Joined: 17-August 12

Re: Saving data to database

Posted 17 August 2012 - 10:38 AM

Sorry, I was just getting off work when I posted that. The game is written in C# **. I am learning C++ separately so little freudian slip there.

The game is a text-based simulation, so graphics are limited to still images. It is an airline based game, the largest XML files are for the airports, with the largest 2 being roughly 100kb. The rest of the XML files are <15kb in size.

The entire game and all its data, is under 20MB of disk space. It is routinely tagging 1.5-2GB of system memory.

My theory regarding the performance issues is that as the game progresses, the number of user and AI flights are increasing, and thus the calculations that the game must process are increasing as well. I have all of the source code and databases on my computer, so I can put them up on here if that would help you give me any guidance.

Again, thanks for the help, and sorry for the typo, the game IS written in C#, not C++ :)
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3617
  • View blog
  • Posts: 11,269
  • Joined: 05-May 12

Re: Saving data to database

Posted 17 August 2012 - 01:39 PM

You should look at is your update algorithm. If it is an O(n^2) algorithm then that would be the first thing to look at. e.g. If you are comparing every aircraft against every other aircraft checking for collisions, this is O(n^2) complexity. One way to speed things up is by reducing n such that you are only checking against aircraft within the same "region". Still O(n^2) but smaller n.

As mentioned above, you should be parsing the XML files and storing the information into objects in memory. If keep on reparsing the XML files to pull out information, that is potentially one source of bottleneck.

Another source of slowdown may simply be due to the garbage collection done by C# with the raw number of objects you are creating and then discarding. MSDN has some tips on reducing the number of garbage collections that happen: http://msdn.microsof...y/ms973837.aspx
Was This Post Helpful? 0
  • +
  • -

#6 fatalpriapism  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 39
  • Joined: 17-August 12

Re: Saving data to database

Posted 17 August 2012 - 06:10 PM

<--- this guy is a rookie. For sakes of me understanding all that sans the last paragraph, please dumb it down a little bit :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1