Jump to content
  • Advertisement
Sign in to follow this  
Todi

What's the best way to data store in memory?

This topic is 3693 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

Hello guys, I was searching in this forum specific and I don't finding anything like my problem. So, if I have passed, sorry the double topic. Following a quote extracted from another forum that i'd posted:
Quote:
Hello people, I'd like to know the best way to store data from an data base, in memory? I'm making an MMOG (Massive Multiplayer Online Game) and I have to store the characters information in my local server for make the changes as fast than SQL query. So, I thought in two ways: First, make an data table like the Delphi Component, to rescue the data from an specific table, then, make all operations suitable. This data table is an ds_grid containing all the informations for each player connected, i.e., an matrix <number of max players> X <number of data fields>. But, it's demands so much job , because I was make all of code to zero. Second, make a data store using ini archieves, utilizing these functions, same I knowing that it's so much slow than memory access, but I have all these functions ready and the organization is much better. Then, I'd like to read some opinions and experiencies about this case. Remember, in a period of time I will commit the data to the data base. Thanks for your answers.
I hope your help. Thanks for your answers! Cordially,

Share this post


Link to post
Share on other sites
Advertisement
You store it in your game. Like inventory data or whatever you happen to be loading from the database when the player logs in and store it as the inventory data structure. Every once in a while you export it like you said or store the changes and export only those.

Basically keep the active data in RAM. If it isn't active then it should be on the database.

I don't really get your "two ways" that you proposed.

Share this post


Link to post
Share on other sites
Quote:
Basically keep the active data in RAM. If it isn't active then it should be on the database.


The data in RAM will be for all characters from players connected, understand? Because, the changes like movements, hp, mp, etc, concerns only the characters online.

So, for example, the player with socket "2" sends to the server an message warning that move your character to the left, so, the server will search in memory looking at the player socket and update the information for the matrix. And, in a period of 10 minutes, all data stored in matrix will be updated to the database.

My problem is exactly this! Make functions for search, retrieve and update information in a matrix in memory where ini archieves have all these functions ready!

Then I ask, it's really feasible?

Share this post


Link to post
Share on other sites
Quote:
Original post by Todi

Then I ask, it's really feasible?


For small data sets, yes.

If your data grows however, you may be looking at several seconds, even minutes, when your server will pause while you are writing the data.

Quote:
First, make an data table like the Delphi Component, to rescue the data from an specific table, then, make all operations suitable. This data table is an ds_grid containing all the informations for each player connected, i.e., an matrix <number of max players> X <number of data fields>. But, it's demands so much job , because I was make all of code to zero.


Unless you want to load entire state from database into some DB-centric structure which handles persistence out-of-box, using a huge table seems inconvenient. Table-oriented structure is fine for SQL, because of Q (query). Without it, it's just a bunch of data.

Will players really be the only state you need to store? And will all objects really have exactly the same data fields?

It depends, if you're planning for a few dozen concurrent players with little state, then this will work, and likely be simplest approach. But if you at some point need to add more persistent state (NPCs, items, quests, ....) writing the state will become a bottle-neck.

Share this post


Link to post
Share on other sites
Quote:
If your data grows however, you may be looking at several seconds, even minutes, when your server will pause while you are writing the data.


In this case, you refer the data in memory or ini files?

Quote:
Will players really be the only state you need to store? And will all objects really have exactly the same data fields?


In moment, yes! The exactly field names, from the characters, are: <id of player>, <nickname>, <reference for sprite outfit>, <reference for avatar image>, <position x>, <position y>, <character direction>, <map location>, <money>, <total win> and <total lose>;

So, I have to keep the data structure somewhere in the server, whatever memory or files, and access this data constantly. The NPC table, have not implemented, yet. But, will be loaded in memory or files too.

Share this post


Link to post
Share on other sites
Quote:
Original post by Todi

In moment, yes! The exactly field names, from the characters, are: <id of player>, <nickname>, <reference for sprite outfit>, <reference for avatar image>, <position x>, <position y>, <character direction>, <map location>, <money>, <total win> and <total lose>;



A typical approach is to use a class/struct representing a character, and have all those fields you mention just be member variables of that class (in some form). You can then have functions that can serialize/deserialize this information and store it in the database periodically (or when more important things change, for example).

When a message is received on a socket, you'll have some form of link between that connection state, and the character object, then just update the information directly.

Share this post


Link to post
Share on other sites
Quote:
use a class/struct representing a character


That's it!
So, I would have only that an list keeping with objects!

Thank you so much! =D

Share this post


Link to post
Share on other sites
INI files are not transactional like a proper database. If something goes wrong when you're writing out the file, you may lose all your data from that file, which players might not appreciate.

I recommend SQLite, which is easy to embed in any program, and is transactional. In fact, it caches so well that you may be able to put all the data in the database and keep it there, rather than keeping a separate copy in memory. Because of the cache, the database will already have it in RAM, so reading is really fast. Writing requires a commit to disk, though, so that will always be slow.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!