r/AskProgramming • • 19d ago

Understanding struct of arrays while using a Data-Oriented Design.

Hi!

I'm developing a video game with C++ and Unreal Engine.

A few days ago, I've read and watch some videos about Data-Oriented Design. After that, I've been thinking about how to improve my code and learn how to do it.

To test it, I have declared this struct:

struct MyStruct
{
  TArray<FTransform> Transforms;
  TArray<FVector> Colors;
  TArray<int32> IDs;
  TArray<bool> Visible;
  TArray<FName> Names;
};

This is a structure of arrays, where each Array contains a different data type.

My question is that I'm not sure if that's a good design in the context of data-driven design.

Perhaps the optimisation would come from using arrays of the same data type, rather than using a structure containing data of different sizes as the data type of an array.

Thanks!

0 Upvotes

21 comments sorted by

View all comments

1

u/mredding 18d ago

My question is that I'm not sure if that's a good design in the context of data-driven design.

That's not a question, that's a statement. What is your actual question? Frame it in a way that it ends with a question mark. If you want my help in C++ and DOD, you need to ask something of substance that I can address.

All I can do is address your doubt and tell you from my experience this is DOD and there is no inherent problem with your code, but there's nothing here of substance to determine if your layout is optimal. If your question is going to reduce to optimal memory layout, you need to show us access patterns.

1

u/VansFannel 16d ago

Wow, I didn't realize I was dealing with a linguist.

My question is that I'm not sure if that's a good design in the context of data-driven design.

1

u/mredding 16d ago

That's still not a question, that is still a statement. I did try to address your doubt. Do you have an actual real question? Anything specific?

1

u/VansFannel 15d ago

My question is that I'm not sure if that's a good design in the context of data-driven design.

1

u/mredding 15d ago

I'm sincerely frustrated on your behalf. Understand that I'm not trying to be a dick toward you, at all. The point I've been trying to make is that I've noticed a communication issue and I've been trying to draw your attention to it. If you can't communicate clearly you're going to have a hard time making progress in school and business.

You still haven't asked a question.

I lament, that you are younger and education took a steep, obvious, and disagreeable dive for you, as I was just making my own exit, at that time. It started with no child left behind. And when that immediately failed as we all knew it would, they changed the grading scale as the easiest thing to remedy. Your education has suffered for it, and the Boomers did this to you.