[virtmach] Exception Safety
David Rush
kumo@bellsouth.net
20 Apr 2000 11:28:05 +0100
thaddaeus.frogley@creaturelabs.com writes:
> I'm considering the following solution. In addition to the programs
> stack/memory space, the VM provides, as an implementation detail, a
> finalisation stack, which contains C++ objects derived from a specific
> virtual base class. These objects are destroyed at the end of a scripts
> lifetime, whether or not it completed execution successfully.
> Can anyone see any problems with this solution, and/or a better solution.
It depends somewhat on the rest of your emmory management strategy, but
you should have one memory management strategy that deals with all
cases: objects which become unreferenced during normal execution or
due to abnormal termination. This way long-running programs won't leak
either. Your strategy may work, but it sounds a little complex on the
C++ side; how many points of failure do you want to have in the
system?
The way I've done this is to treat underlying C++ objects as
completely opaque entities with a garbage-collected handle as the VM
object. When the VM object goes dead, you then delete the C++
object. There are lots of ways you can do the collection, but the real
beauty is that you only have to write 'normal' C++ objects. It also
makes it easier to detect memory leaks in the VM because you can
easily figure out exactly how much memory overhead is needed for each
operation.
But I would be very interested in hearing how your soln works out.
david rush
--
I repeat myself when under stress. I repeat myself when under
stress. I repeat myself when under stress. I repeat myself when
under stress. I repeat myself when under stress. I repeat myself
when under stress. I repeat myself when under stress. I repeat