home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12967 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.3 KB  |  67 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!dsf
  3. From: dsf@cray.com (Dan Frankowski)
  4. Subject: Re: help?? is their a method for solving dynamic allocation problemes in c++
  5. Message-ID: <1992Aug27.092938.6768@hemlock.cray.com>
  6. Lines: 56
  7. Organization: Cray Research, Inc.
  8. References: <1992Aug19.203838.20501@bmw.mayo.edu> <78304@ut-emx.uucp>
  9. Date: 27 Aug 92 09:29:38 CDT
  10.  
  11. In article <78304@ut-emx.uucp> jamshid@emx.utexas.edu writes:
  12. >In article <1992Aug19.203838.20501@bmw.mayo.edu> staniszewski@mayo.edu writes
  13. >[in lines annoyingly over 79 chars long]:
  14.  
  15. >>The problem I am looking at is to trackdown where my dynamic memory
  16. >>problems are using new and delete..
  17.  
  18. >Why is overloading the global operator new() awkward?  And COMMA
  19. >global delete can be overloaded.  See any good, modern, C++ book like
  20. >Stroustrup's _C++ Prog. Lang. 2nd Ed_ or Lippman's _C++ Primer 2nd Ed_
  21. >for more information.  A code example is appended.  Just add your
  22. >debugging alloc package and stir.
  23.  
  24. >Jamshid Afshar
  25. >jamshid@emx.utexas.edu
  26.  
  27. I'm not sure, but doesn't the code need (at least) the corrections below?
  28.  
  29. >#include <new.h>
  30. >#include "debugging_alloc.h" // defines debugging_malloc() & debugging_free()
  31. >
  32.  
  33. extern (*_new_handler)();  // Is this only for cfront?
  34.                            // Will it work even on cfront?
  35.  
  36. >void* operator new(size_t size) {
  37.  
  38.     void *p;
  39.  
  40. >   size = size ? size : 1;    // new(0) must return unique object pointer
  41. >   while ( (p = debugging_malloc(size)) == 0 && _new_handler != 0)
  42. >      _new_handler();
  43. >   return p;
  44. >}
  45. >
  46. >void operator delete(void* p) {
  47. >   if (p)   // ignore "delete 0;"
  48. >      debugging_free(p);
  49. >}
  50.  
  51. Also, my question is, will this cover the global new and delete?  It's
  52. not an overloading.  A function may be overloaded only with different
  53. signatures-- that is, if the parameter lists are different.  In this
  54. case, you are trying to define the same function with the same
  55. parameter list.  I've been trying to get it to work under g++ 1.37 and
  56. cfront 3.0.1, and it hangs in both cases.  Should this work?  Why?
  57.  
  58. (I want to assume global new and delete cannot be replaced-- or if
  59. they can, that it will not show up as __nw__FUi() under cfront 3.0.1
  60. name mangling.)
  61.  
  62. Dan
  63.  
  64. DISCLAIMER: This ain't official Cray business.
  65. -- 
  66. Dan Frankowski            Dan.Frankowski@cray.com     (612) 683-5099
  67.