Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!umich!itivax!scs From: scs@itivax.UUCP (Steve C. Simmons) Newsgroups: comp.lang.c++ Subject: Re: Overloading operator new() Summary: Not as powerful a solution as you'd hoped Message-ID: <298@itivax.UUCP> Date: 9 Oct 88 16:45:36 GMT References: <5949@june.cs.washington.edu> <294@itivax.UUCP> <797@nih-csl.UUCP> Reply-To: scs@itivax.UUCP (Steve C. Simmons) Organization: Industrial Technology Institute, Ann Arbor Lines: 30 In article <797@nih-csl.UUCP> keith@nih-csl.UUCP (keith gorlen) writes: -In article <294@itivax.UUCP>, scs@itivax.UUCP (Steve C. Simmons) writes: --> In article <5949@june.cs.washington.edu> david@uw-june.UUCP (David Callahan) writes: --> >Could someone show me an example of "new" being overloaded and how --> >it would be used? --> --> Someone else has already posted how to do it. I have no examples, --> but can think of a good reason to do it -- exception handling. Since --> new allocates memory, there must be a way of doing garbage collection --> should that allocation become unneeded due to an exception. By overloading --> new, you can go a long way to providing your own garbage collection --> software and make use of more c-style exception processing. Not perfect, --> but a good step. - -I don't see what operator new() has to do with exception handling in C++. -The main problem with trying to do exception handling in C++ is that there -doesn't seem to be a good way to get the destructors called for auto -objects that go out of scope when an exception is raised. operator new() -is only used when allocating objects on the free store with new, not when -they are auto. Could you please explain? Exactly correct. To use this solution, one has to either (a) use only static objects or those explicitly created with new(), or (b) overload the creator/destructor functions to use your garbage-collectable new(). Or a combination of the two. It's not a real elegant solution, but it'd probably work. -- Steve Simmons ...!umix!itivax!scs Industrial Technology Institute, Ann Arbor, MI. "You can't get here from here."