I am developing Darwinian evolutionary modeling. For performance reasons, it is written in C ++. The sim is represented by an instance of World. Animals are represented by instances of Animal, a rather complex object. There are two important methods in the world:
animal_at(int i)
and
evolve(int n).
animal_at returns a non-zero raw pointer to an instance of Animal that represents the ith animal.
evolution advances the simulation, possibly invalidating any pointer returned by animal_at . I want to make sim and animals easily accessible from the outside. I have python-specific bindings, but I'm considering training CORBA or Ice to implement a more universal interface. The problem is how I should exhibit animals. I have two ideas, none of which seem satisfactory: 1) Rewrite the code a bit to use shared_ptr instead of raw ptr and use middleware that understands the semantics of shared_ptr. 2) Create a "deep lazy proxy" that has the same structure as Animal. Its members will be recursively proxy sites for Animal members. animal_at will actually be called at the last moment before referring to the actual data - the pointer will be used and immediately discarded. This would provide the semantics of the "last moment".
I don’t like 1) because I will need to enter the “zombie” state of the object, which seems illogical to me. I do not like 2) because the sole purpose of the proxy server is to implement the "last moment" semantics.
I am looking for an automatic non-intrusive way (using code generation) to achieve this, because I do not want to hide the meaning of the source code. Is there any “official” name for the “last moment” semantics?
Pavel bazant
source share