-
Notifications
You must be signed in to change notification settings - Fork 78
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
Re-use Entity.Id #81
Re-use Entity.Id #81
Conversation
What is the point of reusing Id in addition to reusing "Entity object + it's Id"? There is already reuse of "Entity object + it's Id" you know it, right? |
Not exactly sure what the point of this is. Can you explain the reasoning behind it? |
As @dogwatch said
I guess the reasoning behind desire to reuse just entity.Id is to neutralize (to some extent) constant growth in size of I can only imagine a narrow case when additional Ids retention (doubtfully?) comes in handy:
Only the last case is affected by Ids retention. But the size of those int[] arrays is doubtly the case of optimization. Or do I miss some ordinary case? And having unbound Ids retention is a cheap built-in stuff that sometimes may come in handy? |
Thanks for the explanation and translation, but I think this is above my head with regards to memory management within C#. How is |
Example. class Program
{
static EntityWorld world = new EntityWorld();
static int poolSize = world.EntityManager.RemovedEntitiesRetention;
static void Heartbeat()
{
// Create RemovedEntitiesRetention + 1 entities.
for ( int i = 0; i < poolSize + 1; ++i )
var entity = world.CreateEntity();
Console.WriteLine("ActiveEntities: " + world.EntityManager.ActiveEntities.Count);
Console.WriteLine();
for ( int i = 0; i < world.EntityManager.ActiveEntities.Count; ++i ) {
var entity = world.GetEntity(i);
if ( entity != null )
world.DeleteEntity(entity);
}
world.Update();
}
static void Main(string[] args)
{
Heartbeat();
Heartbeat();
Heartbeat();
Heartbeat();
Heartbeat();
Console.ReadKey();
}
} Output:
To accommodate new entity.Id |
OK, you suggested another case: long running process. Without full Ids retention it will crash eventually with OOM. Entities retention can be turned off by setting I remember the cases when we turned Entities Retention off to get rid of Ids reuse: we had a bug(?) in Systems architecture when sometimes code kept a "reference" to deleted entity's Id and then later tried to get an entity by Id - but got a fresh born one. It was a "quick fix" back then to just turn retention off. |
No. You can not lose indexes. And why if
Maybe, maybe... static void Main(string[] args)
{
var world = new EntityWorld();
world.EntityManager.RemovedEntityEvent += (Entity oldEntity) => {
var newEntity = world.CreateEntity();
Console.WriteLine(oldEntity == newEntity);
Console.ReadKey();
};
var entity = world.CreateEntity();
world.DeleteEntity(entity);
world.Update();
} Output: True ;D |
No description provided.