Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are memory requirements O(entities * component types)? #201

Open
newobj opened this issue Nov 2, 2017 · 2 comments
Open

Are memory requirements O(entities * component types)? #201

newobj opened this issue Nov 2, 2017 · 2 comments

Comments

@newobj
Copy link

newobj commented Nov 2, 2017

Reading the code, it seems to me like components share the index of their Entity, e.g. the Position Component for Entity #1,000,000 will the 1,000,000th Position Component in the Position Component Pool.

Am I understanding this correctly? If I have 1,000,000 entities, and there is one instance of the Foobar component, but it happens to be on entity 999,999, then we'll have to eat the memory of unused 999,998 unused components in the Foobar pool?

Am I reading the code correctly? If I'm wrong, can you help me understand how?

I'm mainly looking at EntityManager::assign to make this determination, specifically in the placement new:

::new(pool->get(id.index())) C(std::forward<Args>(args) ...);

where pool is the component pool, and id is the entity id.

@alecthomas
Copy link
Owner

With the default storage implementation, that is correct, yes.

@newobj
Copy link
Author

newobj commented Nov 2, 2017

Thanks Alec. So, taking this a bit further, am I correct in understanding that iterating (EM::each) over a particular component type is linear in the number of entities, not in the number of component type instances?

I'm curious whether this strategy was the simplest thing that worked generally, and/or if you put a lot of effort into other approaches that didn't pan out? I'm writing my own ECS framework as a learning exercise and trying to keep scale of component instances separate from entity instances. The exercise is a bit silly since EntityX is so awesome, but never the less... :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants