Budman: Thanks for clarifying the stack vs. pure static data.
BTW, when I say anything that's not allocated by "new" or "malloc()" is basically static data, I mean it doesn't require a separate allocation. In a game, most everything is going to be dynamically allocated at some point (your entities, for example), so what matters is how many heap allocations it takes when loading a new entity, for example. By using all non-dynamic variables, you can reduce it to 1 (and you can actually reduce the number of allocations below 1 per object if you implement some sort of pooling strategy).
I don't know what a link object is, but based on your code I think the equivalent is an iterator:
I didn't try running this, but hopefully it doesn't have any errors. Note: There may be a better way to do this, but I'm not sure. Personally I think they should have made it so push_front() returns an iterator at the newly added item.
BTW, when I say anything that's not allocated by "new" or "malloc()" is basically static data, I mean it doesn't require a separate allocation. In a game, most everything is going to be dynamically allocated at some point (your entities, for example), so what matters is how many heap allocations it takes when loading a new entity, for example. By using all non-dynamic variables, you can reduce it to 1 (and you can actually reduce the number of allocations below 1 per object if you implement some sort of pooling strategy).
What is the equivalent in CPP to a link object?
Here is my entity constructor and destructor. You can see when it is created it gets added to the world entities list. How can I remove it from the list upon deletion?:
Here is my entity constructor and destructor. You can see when it is created it gets added to the world entities list. How can I remove it from the list upon deletion?:
I don't know what a link object is, but based on your code I think the equivalent is an iterator:
class Entity { public: Entity(); ~Entity(); private: list<Entity*>::iterator link; }; Entity::Entity() { pWorld = World::current(); pWorld->entities.push_front( this ); link = pWorld->entities.begin(); //returns an iterator at the newly added item } void ~Entity() { pWorld->entities.erase(link); pWorld = null; }
I didn't try running this, but hopefully it doesn't have any errors. Note: There may be a better way to do this, but I'm not sure. Personally I think they should have made it so push_front() returns an iterator at the newly added item.