Dirk Reiners wrote:
Hi Fredrik,
On Fri, 2005-08-12 at 15:13 +0200, Fredrik Andersson wrote:
Hi Andreas
Thanks, but I would prefer to get the value programmatically.
What say you?
Well, we somewhat on purpose decided to not allow that, as it lends
itself to code like "while(refcnt > 0) subRef();", which would wrack
havoc on multi-threaded apps. It is a case of trying to not let the
users shoot themselves in the foot and entice them to do their ref
counting cleanly, but it does have problems for debugging.
Code like that will, in general, wreak havoc on any application, as
other RefPtrs will not be informed that their object has been destroyed,
so accesses via them will lead to undefined behaviour (most likely
crashes). This issue is fixable with either weak-pointers (such as those
used with boost::shared_ptr) or some other
is-(being)-destroyed-notification mechanism.
My 0.02 SEK on design of reference counting systems is that the
preffered way is to disallow users to change the ref-count explicitly
(i.e. encapsulate this in the well-behaved RefPtr-class, and similar
structures) but allow them to access this for reading (so that
deviations from expected ref-count can be checked, in case of unwanted
cycles and such). Manual ref-counting is, from my experience, quite
error-prone. However, I don't know if this is an option for the OpenSG
user base, as they might be doing a lot of explicit add/sub-refs.
On a similar topic, is there some debug mechanism (existing or planned)
to report whether all OSG-objects have been freed upon applicaiton exit
(or before that)? Some ref-counted systems keep a global count over the
number of live ref-counted objects at any time, and this number can be
used to detect such errors. I kind of like being able to assert those
kind of things.
Best regards
/Marcus
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users