home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!agate!forney.berkeley.edu!jbuck
- From: jbuck@forney.berkeley.edu (Joe Buck)
- Newsgroups: comp.lang.c++
- Subject: Re: strdup() Was: Re: Renew?
- Date: 29 Jul 1992 19:54:15 GMT
- Organization: U. C. Berkeley
- Lines: 25
- Message-ID: <156t17INNq72@agate.berkeley.edu>
- References: <1992Jul27.201834.13654@Warren.MENTORG.COM> <1992Jul28.163356.3019@taumet.com> <1992Jul29.155252.7632@cbnewsk.cb.att.com>
- NNTP-Posting-Host: forney.berkeley.edu
-
- In article <1992Jul29.155252.7632@cbnewsk.cb.att.com> hansen@pegasus.att.com (Tony L. Hansen) writes:
- >By the way, at least one person has posted a poor version of strdup() which
- >didn't check the return value of new. Here's my contribution. As you can
- >see, it is a very straightforward function:
- >[ nstrdup that checks value of new ]
-
- Sorry, Tony, I disagree. This is the whole reason that exceptions were
- added to the language, so we wouldn't have to do this. In the case of
- new failures, there is already a mechanism present: the "new handler".
-
- If nstrdup checks for new returning 0, we then have to check for nstrdup
- returning 0, and so on. Your nstrdup has just passed the problem on to
- someone else.
-
- The proper approach is to use set_new_handler establish a handler to catch
- new returning 0, and have it either free up some memory or exit the
- application cleanly. Those in memory-poor environments (IBM-PCs and
- such) may disagree.
-
- Given this philosophy, my version was just fine, thank you.
-
-
-
- --
- Joe Buck jbuck@ohm.berkeley.edu
-