data-oriented and data-driven programming.

528 views

I’ve got a good idea of object-oriented, but explanations of the other two just confuse me.

In: Technology

2 Answers

Anonymous 0 Comments

Data-oriented and data-driven programming are two pretty distinct concepts, but not exclusive of each other.

I’ll explain using a game as an example (because that’s what I’m familiar with).

Data-driven means that the functionality of the program is driven by what data is fed into it.

Here’s an example. One way to make the menus for your game is to just write code to build the menus. So you’d have code that places all the buttons, and then code that decides what each button does. But a data-driven way to do it would be to have menus designed in an editor (or even some sort of HTML like text format) which is loaded into the game for the code to interpret. Rather than buttons being hardcoded to do particular things, you can assign actions to buttons in the editor.

Data-oriented programming is a more technical concept. The basic idea is to write code around how data is laid out in memory so that your code is faster. You need to know a bit about how RAM and CPU caches work to understand why you would do this. Reading from RAM is slow compared to reading data from the CPU cache. The CPU automatically transfers data from RAM into the cache when you access it. It assumes the next bit of data you’re probably going to need will be directly after the bit you just used. If that assumption is incorrect you get a “cache miss”, meaning it has to go off and read data directly from RAM again. So you want to avoid that, and as much as possible make sure the next bit of data you need is just after the bit you’ve just used.

A simple example of data oriented thinking would be to use contiguous arrays instead of arrays of pointers. Say you have a list of things that you want to update. The typical object oriented way to do that would be to create separate objects, and then have an array of pointers to those objects. That’s not very cache efficient because each object could be in a completely different place in memory. A data-oriented approach would be to have an array where each object is placed next to each other in memory. That means when when you go through that list to update each one, it should already be in the cache.

Sorry if the data-oriented explanation is a bit difficult to understand. It’s a fairly advanced concept.

You are viewing 1 out of 2 answers, click here to view all answers.