|
From: Roger H. <rog...@mi...> - 2004-06-24 13:27:12
|
> Assuming this is all correct, the reader will be wondering: Why do > Dispose a Q3Object, but I can only GetReference to a Q3SharedObject? > It doesn't seem very parallel. And, is it safe to call Q3SharedObject > on something that is not, in fact, a Q3SharedObject (and what's an > example of a Q3Object like that)? > > I don't have good answers to these questions, so I'm hoping you do! An object knows how to dispose of itself, just like it knows how to submit itself or how to make a copy of itself. We do not need separate routines to dispose of a box, an ellipsoid, a polygon etc so we do not need a separate routine for shared and unshared objects. Using C++ terminology you just say "delete fred" and the system uses the object's virtual destructor (and any base classes virtual destructors in turn). The only thing that Q3Shared_GetReference does is to increment the reference count. Why It was not called something more appropriate I don't know. As an unshared object does not have a reference count it is both pointless and invalid to call GetReference on one. To get a reference to an unshared object you just assign its pointer to another pointer, but you have to keep track (in the programmer's head) of when the object is no longer needed. Actually you can do the same thing with shared objects, and I do, but only in simple pieces of code where it is easy to track the pointers. For more complex cases this is impossible and the small overhead of calling Q3Shared_GetReference and Q3Object_Dispose is worth every nanosecond. Roger. |