Path: utzoo!attcan!uunet!nih-csl!keith From: keith@nih-csl.UUCP (keith gorlen) Newsgroups: comp.lang.c++ Subject: Re: Overloading operator new() Summary: What does overloading new have to do with exception processing? Message-ID: <797@nih-csl.UUCP> Date: 7 Oct 88 20:01:23 GMT References: <5949@june.cs.washington.edu> <294@itivax.UUCP> Organization: NIH-CSL, Bethesda, MD Lines: 25 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? Thanks. -- Keith Gorlen phone: (301) 496-5363 Building 12A, Room 2017 uucp: uunet!nih-csl!keith National Institutes of Health Internet: keith%nih-csl@ncifcrf.gov Bethesda, MD 20892