-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Denker wrote: | On 01/18/2008 09:05 AM, till busch wrote: | |> i've started to run fg through valgrind. i found this to be a nice option for |> getting an overview over the code in flightgear. | | 1) This is important, valuable, and overdue. | | 2) It's going to be a lot of work. That's because | | 2a) Although it is easy to write valgrind-clean code, once | somebody has written unclean code it is not necessarily | easy to clean it up. | | 2b) Although some of the FGFS code is exemplary c++ code, | some of it is not. Some of it is what we call "c-- code | compiled with the c++ compiler". The point is is, c++ is a | different language from c--, and unfortunately some of FGFS | code exhibits a deep non-understanding of the purpose and | capabilities of the c++ language. | | This is related to the recent discussion (in another thread) | of "memory management". C++ is perfectly capable of automatic | memory management, if allowed to do so. Sure, c++ gives folks | enough rope to hang themselves (in contrast to e.g. java, which | gives them less rope) but c++ does not /require/ anyone to hang | themselves. | | As a simple guideline, with few exceptions, one should put new | and delete in constructors and destructors, and then let the | automatic memory management do its thing. Yeah, I know this | is more work than manually newing and deleting things, but it | makes the code vastly more reliable, more maintainable, more | readable, more reusable, and more extensible. | Actually, we want to avoid writing explicit deletes as much as possible, as that need is the source of most memory leaks. We have two classes for smart, reference- counted pointers, osg::ref_ptr and SGSharedPtr which should be used for all long-lived, shared objects. It's unfortunate that there are two choices, and I've contemplated removing the simgear version in favor of OSG, but I think SGSharedPtr has some performance advantages in multi-threaded situations. Anyway, use osg::ref_ptr for scene-graph related stuff.
| There's waaay too much c-- style manual memory management in | FGFS, for no good reason ... and waaay too many memory leaks. | Tim -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFHkdOHeDhWHdXrDRURAmBZAJ9V3ri6ihfeee2u/Av7RzsCrwrjTgCdEXFt 0S2rxBwctvsU5yBWjcs9Xlc= =IXd4 -----END PGP SIGNATURE----- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel