-
-
Notifications
You must be signed in to change notification settings - Fork 95
Svelto.ECS memory layout
One datastructure to rule them all, we could say. Entities are stored in Svelto.ECS using just one unique (but complex) data structures. The entity components are stored according their types and no boxing will ever happen. When EntityStructs are used, the data is laid out sequentially for maximum performance, however the use of groups will dictate the grouping in the corresponding c# arrays.
For a long explanation, check this: https://github.com/sebas77/Svelto.ECS/issues/36
short one:
Entity components are stored sequentially regardless the entity types that generate them. When an entity component array is returned through the entitiesDB query methods, it will contain all the entity components of all the entities that generate that specific component. However this is true as long as they belong to the same group. Grouping can be then exploited to split how entity components are laid out in memory. This becomes very handy when you want to write engines that need to iterate over different entity components using the same array index.
If you have an Entity Type X generating the components A and B and an Entity type Y generating the components B and C, you cannot iterate the entity arrays of A and B with the same index, as they will have different length. However as long as X and Y are generated in two different groups, then you can rest assured knowing that the components of A and B of X are just the ones generated by X
Related articles: