# Is it bad to store other memory in a system, alongside the components buffer using an Entity-Component-System architecture (ECS)?

I'm currently writing a simple ECS architecture for an engine and I have the fundamentals in place but after reading up on this architecture, it is designed in such a way that the memory is contiguous for all of the components and systems.

My understanding is that the components should be stored right after each other so they are not somewhat fragmented in memory? So that way when I update all of the components, the cache prefetcher can help out performance by fetching the next lot of components (limited understanding) without jumping around.

class system1 final
{
public:
//...

private:
std::vector<component1>         m_components;
};

class system2 final
{
public:
//...

private:
std::vector<component2>         m_components;
};


Then in some manager, you would initialize the systems so that they are as close as possible in memory.

But what if I wanted to allocate additional memory in the systems? Like a few extra buffers for dealing with system-specific information. That would then separate the component buffers so they are no longer next to each other.

class system1 final
{
public:
//...

private:
std::vector<component1>         m_components;
std::vector<int>                m_somebuffer;
std::vector<int>                m_someOtherBuffer;
};

class system2 final
{
public:
//...

private:
std::vector<component2>         m_components;
};

• Would this cause any problems and does this break the whole ECS principle?
• What should I be considering here for maximum performance without stumbling on issues later?

I don't want to optimize prematurely but knowing what makes an architecture fast and somewhat optimal during development is an interesting topic for me. Any input is greatly appreciated.

However, there is one thing in your architecture which is usually not what you do in an ECS-by-the-book architecture, and that's that each system owns the components it manages. You usually don't have a 1:1 relationship between systems and components. There are often components shared by multiple systems and systems which operate on multiple components. For example, you might have a system MovementSystem which uses the components Position and Velocity and a separate CollisionSystem system which uses the components Position and BoundingBox.