|
From: Joseph J. S. <jo...@st...> - 2004-06-24 14:50:18
|
At 4:09 PM -0700 6/23/04, James W. Walker wrote: >>When that reference is about to disappear -- for example, because >>it's in a local variable that is about to go out of scope or be >>assigned a different value, or in an object that is being destroyed >>-- then you must call Q3Object_Dispose to let Quesa know that there >>is one less reference to that object. > >The first use of the word "object" here refers, I assume, to >something like a C++ object, while the last use refer to a Quesa >object. This may cause confusion. Your interpretation is right, but I agree, that's confusing. I'll change it. >>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. > >This does not bother me, though maybe I'm just used to it. For >shared objects, "dispose" has a special meaning. But one would expect GetReference to take a Q3Object, and under the hood it would just have a special meaning for shared objects. >> And, is it safe to call Q3SharedObject > >You mean Q3Shared_GetReference? Yes, sorry about that... >> on something that is not, in fact, a Q3SharedObject > >If we look at the source code in Quesa, we see that >Q3Shared_GetReference will have an assertion failure and then return >NULL. Well that's not very pleasant. It makes the whole use of Quesa objects much more confusing. (See below.) >>(and what's an example of a Q3Object like that)? > >Look at the typedefs of TQ3SharedObject etc. in Quesa.h, and you see >that views and picks are examples of non-shared Quesa objects. So would you agree that the proper rule is this: - When you want to make another reference to a Quesa object, and know its type, you must look up that type in Quesa.h and see if it derives from TQ3SharedObject. If it does, call Q3Shared_GetReference; if not, just make your other reference and don't worry about it. - When you're done with a Quesa object that may also be in use elsewhere, you must again look it up to see if it's shared; if it is, call Q3Object_Dispose; if it's not, then don't do so or you'll be pulling the rug out from under some other part of your app. - If you have some generic routine that takes a TQ3Object and makes another reference to it, then you can't know at compile time whether or not it is shared, so you must find out dynamically somehow whether or not to call Q3Shared_GetReference... but how? I'm glad we're having this discussion, because even after all these years, I still don't seem to have a firm grip on Quesa/QD3D's reference-counting system! Thanks, - Joe P.S. This is all for the Using Quesa book, so once I'm clear on it I'll try to write it up so that we never have to explain it again! -- ,------------------------------------------------------------------. | Joseph J. Strout Check out the Mac Web Directory: | | jo...@st... http://www.macwebdir.com/ | `------------------------------------------------------------------' |