An in-memory database?

Discussion and feedback on Construct 2

Post » Thu Nov 22, 2012 2:20 am

I've been toying with the idea of an in-memory database, for purposes of handling a large number of objects and data (imagine a simulation game). Due to the limitations of a browser-based game, it'd have to be an internal database engine sorts of. So, an in-memory database.

I've looked around a bit, apparently SQLite can be created in memory only (with the ":memory:" as filename), so that should work in browser environment. The content could be saved to webspace and loaded into the in-memory database. The caveat is memory usage, but I'm not considering anything huge anyway. Just a few tens thousands objects.

What say you? Would it be worthwhile to have such a feature?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Nov 22, 2012 6:28 am

Anything that would boost the performance is welcome.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
71
S
19
G
19
Posts: 1,919
Reputation: 16,910

Post » Thu Nov 22, 2012 2:48 pm

Could you get away with just creating a large array?
Scirra Founder
B
358
S
214
G
72
Posts: 22,946
Reputation: 178,333

Post » Thu Nov 22, 2012 3:09 pm

Sure, however that's counterproductive. Moreover, it isn't really flexible for a tree-like object hierarchy.

Imagine a typical space map: galaxy > clusters/constellations > stars > planets > moons. Some planets may have some moons or none at all, some stars may have no planets or up to dozen etc., there is a lot of dynamic data.

So basically database is a set of sets. Alternatively we could do with a "set" (think javascript Object with a bunch of variables) and implement our own form of database. Perhaps with hashtables. Would require a lot of effort setting up.

The point of a database is quick lookups and changes with tens of thousands or even more objects. I'm not sure it'd be a good idea to manually iterate over each set. Then there is the whole magic with indexes.

Well, I'm not really that knowledgeable, however there is a demand for more flexible data structures capable of handling thousands of entries. We can only go so far with arrays and variables.

Hm, XML object could serve as some sort of database, however I'm not sure about its efficiency.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Fri Nov 23, 2012 3:03 am

Booyah !

I don't understand a lot of what is being said right here but anything that could help C2 is welcomed ! :D

Cheers
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Post » Wed Feb 27, 2013 5:16 am

Did a search, and this appears to be the most recent post on the subject.

I am missing this kind of functionality.

Specifically, I would like to see a 'user-defined data type' or what is called a structure or 'struct' in C:

psuedo code of no particular language:

structure coord{
   x : number;
   y : number;
};

structure Enemy{
   ID : number;
   coord : coord; // <-- uses the struct defined above.
   onscreen : boolean;
   damaged : boolean;
   name : text;
   attack : number = 1;
   defense : number = 1;
   weaponModules : array[0..10] of hardpoints; //<-- an array of a struct.
};   

Enemies : array[1..100] of Enemy; //<-- an array of the Enemy structure.

With this kind of structure, the code is a little better at self-documenting, as opposed to using plain arrays. For example:

Accessing Enemies[i].weaponModules[j].hitpoints is far more readable than something like aEnemyWeaponModules[i,j,4], where you have to leave yourself a note that Z-index 4 is 'hitpoints'. And you have to know how you are associating separate arrays that contain all the Enemy parameters, or else the documentation load gets worse and the code gets more cryptic if you are cramming everything into one array called aEnemies(x,y,z)

For all intents and purposes, it is a record with fields, as in a data base, with fields consisting of one or any of the base types of the language, which for C2 is essentially a 'number', boolean, or string (text). But it also can contain another struct as one of it's defined fields, and it can define an array of any of the three C2 base types or any previously defined structures. So you could have a hierarchy of structures, where potentially, only the lowest levels of the hierarchy actually contain base types.

For now, if I just want an instance of this kind of record, or want several instances to act as a table of records, then creating instance variables within an Array will be the closest I can come, I believe, with the exception that it can't create an array of instance variables (i.e., sub-arrays), nor can it create an instance variable, or 'field' of a type other than number, Boolean, or text. That, and the instances can't quite be referenced like an array, though C2 does provide good ways to pick specific instances or process all or a subset of instances, so maybe that is not an issue really.

Then to realize the full benefit, I would want to be able to write a function that takes as an input parameter (or input/output parameter, or typically called a by-ref parameter in some languages) one of these structures.

Of course, the structure concept and XML mesh well together, so you could have the XML plugin write a structure out to XML, or read an XML file into a structure, facilitating saving and loading save-games or game-options, or other persistent data.

                                                  Jaycephus2013-02-27 05:42:14
B
14
S
4
G
1
Posts: 26
Reputation: 1,747

Post » Wed Feb 27, 2013 5:26 am

I meant to add that there is more than one way to accomplish the same thing, and a 'class object' approach, where there is something like a 'struct' plug-in, and we would just create as many instances as we need is fine as long as the above functionality is included. With instances, as opposed to an array, you can create and destroy however many you need in a given time-frame, optimizing memory usage. But this plugin would need to create instances of other definitions in order to duplicate the structure within a structure hierarchy.
B
14
S
4
G
1
Posts: 26
Reputation: 1,747

Post » Wed Feb 27, 2013 5:34 am

Could also make a light blank plugin object. Separate every new one off into subdirectories. Use the instance variables for data. Create as many as you need.

When you need to save offload that organization into web storage.

I've also been messing around with node recently and there's a lot of buzz around MongoDB. I have no experience with it though.
B
72
S
10
G
6
Posts: 104
Reputation: 7,550


Return to Construct 2 General

Who is online

Users browsing this forum: humanescape and 10 guests