Generally you do not want to prevent the GC from moving around anything - especially in your case (transactional objects), where I would rather consider options like:
- making objects savable+restorable=serializable
- doing it with some sort of manager (maybe this fits well to the idea you had with pointers) that you can pass closures!
Second option explained:
class VariableManager
{
private Action<int> setter;
public void VariableManager(Action<int> setter)
{
this.setter = setter;
}
public void SetValue(int i)
{
setter(i);
}
}
Simply create the manager via new VariableManager(i => yourInt = i)
and viola - there you have your desired semantics without pointers!