Wednesday, 13 April 2016

c++ - which is faster, a single array of object, or multiple array of data attributes?

Here is a simplified example. Note that I chose simple types, but in an application I might have many more attribute



struct object
{
float a, b;

int c;
};
vector objects;


or



vector a, b;
vector c;



In a game application where you access each attribute at least once, performance might vary. The game loop will run through the whole index, no matter what.



I know the first example is much more convenient (much easier to organize code with one single struct) and that it might depend on what the application is really doing, but isn't the second example more cache friendly ?



I know it's not the proper way to make an application at first with the Knuth premature optimization thing, but I'd just like to know... I've read this in a gamedev slide once and I'm wonder if it's true or not, and why.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...