An in-memory database?

0 favourites
  • 8 posts
From the Asset Store
Build Social Apps, Chats and Advanced Lists using Firebase Realtime-Database
  • 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?

  • Anything that would boost the performance is welcome.

  • Could you get away with just creating a large array?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Booyah !

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

    Cheers

  • 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.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.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)