home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!dsf
- From: dsf@cray.com (Dan Frankowski)
- Subject: Re: help?? is their a method for solving dynamic allocation problemes in c++
- Message-ID: <1992Aug27.092938.6768@hemlock.cray.com>
- Lines: 56
- Organization: Cray Research, Inc.
- References: <1992Aug19.203838.20501@bmw.mayo.edu> <78304@ut-emx.uucp>
- Date: 27 Aug 92 09:29:38 CDT
-
- In article <78304@ut-emx.uucp> jamshid@emx.utexas.edu writes:
- >In article <1992Aug19.203838.20501@bmw.mayo.edu> staniszewski@mayo.edu writes
- >[in lines annoyingly over 79 chars long]:
-
- >>The problem I am looking at is to trackdown where my dynamic memory
- >>problems are using new and delete..
-
- >Why is overloading the global operator new() awkward? And COMMA
- >global delete can be overloaded. See any good, modern, C++ book like
- >Stroustrup's _C++ Prog. Lang. 2nd Ed_ or Lippman's _C++ Primer 2nd Ed_
- >for more information. A code example is appended. Just add your
- >debugging alloc package and stir.
-
- >Jamshid Afshar
- >jamshid@emx.utexas.edu
-
- I'm not sure, but doesn't the code need (at least) the corrections below?
-
- >#include <new.h>
- >#include "debugging_alloc.h" // defines debugging_malloc() & debugging_free()
- >
-
- extern (*_new_handler)(); // Is this only for cfront?
- // Will it work even on cfront?
-
- >void* operator new(size_t size) {
-
- void *p;
-
- > size = size ? size : 1; // new(0) must return unique object pointer
- > while ( (p = debugging_malloc(size)) == 0 && _new_handler != 0)
- > _new_handler();
- > return p;
- >}
- >
- >void operator delete(void* p) {
- > if (p) // ignore "delete 0;"
- > debugging_free(p);
- >}
-
- Also, my question is, will this cover the global new and delete? It's
- not an overloading. A function may be overloaded only with different
- signatures-- that is, if the parameter lists are different. In this
- case, you are trying to define the same function with the same
- parameter list. I've been trying to get it to work under g++ 1.37 and
- cfront 3.0.1, and it hangs in both cases. Should this work? Why?
-
- (I want to assume global new and delete cannot be replaced-- or if
- they can, that it will not show up as __nw__FUi() under cfront 3.0.1
- name mangling.)
-
- Dan
-
- DISCLAIMER: This ain't official Cray business.
- --
- Dan Frankowski Dan.Frankowski@cray.com (612) 683-5099
-