using arrays to get best memory alignment and cache use, is it necessary?

Posted by Alberto Toglia on Stack Overflow See other posts from Stack Overflow or by Alberto Toglia
Published on 2010-05-22T19:33:07Z Indexed on 2010/05/22 19:40 UTC
Read the original article Hit count: 181

I'm all about performance these days cause I'm developing my first game engine. I'm no c++ expert but after some research I discovered the importance of the cache and the memory alignment.

Basically what I found is that it is recommended to have memory well aligned specially if you need to access them together, for example in a loop.

Now, In my project I'm doing my Game Object Manager, and I was thinking to have an array of GameObjects references. meaning I would have the actual memory of my objects one after the other.

static const size_t MaxNumberGameObjects = 20;
GameObject mGameObjects[MaxNumberGameObjects];

But, as I will be having a list of components per object -Component based design- (Mesh, RigidBody, Transformation, etc), will I be gaining something with the array at all?

Anyway, I have seen some people just using a simple std::map for storing game objects. So what do you guys think?

Am I better off using a pure component model?

© Stack Overflow or respective owner

Related posts about c++

Related posts about memory-management