Public Group

# What is Data Oriented Programming?

This topic is 3159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've just gotten my head around the concept of OOP, when someone on this forum posted a link to DOP... I have no idea what DOP is, never heard of it before. So I read the link, and I didn't understand it. I googled for more notes/articles on DOP but didn't understand any of them. They all barraged me with a mass of technical details at me and the concept got lost.

What is Data Oriented Programming?

##### Share on other sites
Googling found me this, which looks fairly comprehensive and easy to understand.

The information I gleaned from my 5 minute gloss-over is that Data Oriented Programming allows you to de-couple tightly-bound architecture into one that is 'driven' by data rather than explicit and static interfaces definitions. Think dependency injection with data rather than, e.g. static spring files. It's not a replacement for OOP, it's at a higher level than that.

On page 10 they have a diagram of a producer and a consumer with the interface between being a data model rather than an explicit definition. This implies loose coupling between components which would make bespoking the architecture far easier and within the reach of the end user rather at the initial design stage.

It's an interesting concept from a business enterprise application perspective but I'm not sure it would suit game development unless it was perhaps some kind of game designer application.

##### Share on other sites
it COULD also be related to optimizations like:
This

In a very similar fashion to optimizing code for SSE instructions, you try to bunch used data close together.
Large structures that conglomerate data together result in processes that have signficantly low data usage rates.
Consider any class with a "bool needsUpdate" member. In a loop like:
for ( all creatures )  if ( creature->needsUpdate )    creature->Update();

You end up reading in 128bytes of cache line to read a single bit, and if it is false, you discard all 128bytes you just read in.

This guy goes through a lot more of it focusing on a component archetecture, and explains why breaking up your data into more focused components can make things much faster.

##### Share on other sites
To quote Mike Acton:
Quote:
 the point of any program is simply to transform data from one form into another and nothing else. And as one "solution" which ignores the real core problems of development is developed and others over time are built on top of that idea, and so on, we're left with systems that are over-designed, perform poorly and simply do not accomplish what they intended to in the first place - and certainly not well. I continue to suggest that we all take a step back from what we're doing and the methods we're using to solve problems and try to remember what the real issues are.

Check out pitfalls of OOP for an example where designing around data (instead of designing around code) can give big performance benefits.

##### Share on other sites

To me, it looks like the author ends up with a component-based design, where each component type is stored in and processed by an appropriate system. Renderables are processed en-masse by the rendering system, physical objects are stored in and processed by the physics engine, and so on. Game objects only hold references to the components they consist of: for example, an enemy would reference a renderable, physical and AI component, while a trigger would only have a physical and a script/action component.

I never looked at it from a performance angle, but it makes sense.

##### Share on other sites
Do you still use classes in DOP?

Is DOP a different way of organising and constructing your classes with a view to making your code more efficient?

##### Share on other sites
Quote:
 Original post by N3wbieDo you still use classes in DOP?Is DOP a different way of organising and constructing your classes with a view to making your code more efficient?

In general your applications will mix OOP and DOP. DOP is more for dealing with large quantities of data and efficiently working with them, where OOP works well for everything else.

I only use DOP in specific classes or sub systems, later in the cycle of an app one may find it appropriate to use for optimization passes too.

KulSeran's example is the typical one most developers run into. The larger the class is you are looping through the worse your data access is. Cache misses can be detrimental to apps trying to be efficient and DOP takes into consideration the layout of your data and how the system actually accesses it.

##### Share on other sites
Quote:
Original post by Hodgman
To quote Mike Acton:
Quote:
 the point of any program is simply to transform data from one form into another and nothing else. And as one "solution" which ignores the real core problems of development is developed and others over time are built on top of that idea, and so on, we're left with systems that are over-designed, perform poorly and simply do not accomplish what they intended to in the first place - and certainly not well. I continue to suggest that we all take a step back from what we're doing and the methods we're using to solve problems and try to remember what the real issues are.

Check out pitfalls of OOP for an example where designing around data (instead of designing around code) can give big performance benefits.

My god! That is the actual article I was searching for and didn't find when I was posting. Thanks.

##### Share on other sites
Hmmm, so would I be right in saying that 2 of the key concpets are:

1. Organize your code in terms of data structures.

2. Use vectors to store your data structures wherever possible.

So if I have a simulation of a solar system, I might have a vector of sizes, a vector of masses, a vector of planet types, a matrix of positions, etc?

What about if I wanted to model the orbits using a Newtonian system? I guess I would have a matrix representing the graviational field acting on each massive item in the solar system?

And what about the relationship between the field and the position over time? Would this be a function or as I think I read somewhere a matrix transformation representing this relationship?

Would this be preferable to OOP? Isn't this just good procedural coding? I mean with a bit of thought that's probably the approach I would have taken anyway if I weren't using OOP. In fact, though I can see the massive benefits of classes, I find the restrictions they have too restrictive making coding more of a chore, and that you spend too much time worrying about them and the language syntax. I think I would likely prefer to code the way I just described.

[Edited by - N3wbie on June 25, 2010 10:27:24 AM]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 13
• 13
• 9
• 25
• ### Forum Statistics

• Total Topics
634449
• Total Posts
3017509
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!