r/AskProgramming • • 18d 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

-3

u/DXTRBeta 18d ago

That’s not a good model. You obviously have a bunch of things that have these properties, so design one object that defines a single instance of your “thing” and then make an array of them.

See what I mean?

-1

u/VansFannel 18d ago

An object? Like the one I used to use in Object-Oriented Design?

Do you know that I'm asking about Data-Driven Design?

See what I mean?