3

My application is similar to a very simple CAD program. The user can create and modify a database of several thousand, simple 3D objects (e.g. cubes and spheres). Each object has a position, orientation, and size. I anticipate having these objects serialized in the database.

I want to render objects in the database in 3D views. The 3D views could be the entire database or a particular query (e.g. objects of a certain size). The views should always reflect the current state of the database as objects are added/removed.

So my question is: how can I have the render loop efficiently access the database? These are the options I can think of:

  1. Give render loop direct access to database. Deserialize objects and render at each loop. This seems inefficient, but maybe not as bad as I fear.
  2. Give render loop direct access to database, but try to store data in such a way that it does not need to be serialized.
  3. Create another data structure that always mirrors the database, but is more easily rendered.

1 Answer 1

2

In general, it doesn't seem wise to bind one of the potentially slowest parts of an app (disk-based DB access) to one that's performance sensitive (3D rendering).

I would consider either a Repository-style abstraction where you keep both an in-memory representation of the data and the DB store, flushing to the latter when the user is done editing; or, if the size of the data is manageable, an in-memory store such as Redis or memcached.

All that said, I would only consider the above if you're actually running into performance or data consistency problems with a simpler setup.

2
  • This is a great answer. By using a repository pattern the interfaces can stay the same, but the repository can choose to use any type of caching solution without needing to change code in the renderer. Dec 29, 2016 at 0:36
  • I'm sorry, I forgot to mention I was planning to use an in-memory database, via SQLite. My concern was that since SQLite can't store general objects (just byte arrays), I'd have to deserialize them every loop. Do you think that's a concern I should try to avoid? Dec 30, 2016 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.