Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uwm.edu!uwvax!heurikon!ex.heurikon.com!daves From: daves@ex.heurikon.com (Dave Scidmore) Newsgroups: comp.lang.c++ Subject: Re: Why no renew Message-ID: <184@heurikon.heurikon.com> Date: 14 Mar 91 18:47:57 GMT References: <10895@pasteur.Berkeley.EDU> <1991Mar3.053504.14027@mathcs.sjsu.edu> <281@nazgul.UUCP> <1991Mar14.042611.14921@mathcs.sjsu.edu> Sender: news@heurikon.heurikon.com Reply-To: daves@ex.heurikon.com (Dave Scidmore) Organization: Heurikon Corporation, Madison, WI Lines: 51 In article <1991Mar14.042611.14921@mathcs.sjsu.edu> horstman@mathcs.sjsu.edu (Cay Horstmann) writes: >In article <281@nazgul.UUCP> bright@nazgul.UUCP (Walter Bright) writes: >>Ah, but you can do it! Simply overload the global operator new to use >>calloc. It's even portable! > >I cannot call such a solution portable. > >If my code relies on the global operator new doing one thing and your >code relies on the global operator new doing something different, we cannot >share code for the same program. (The ARM [p.60] has a similar comment.) > >I repeat my request that operator new should default to initializing the >memory with the logical 0 value for the type allocated (almost always an >all-0 bit pattern, but then who knows how 0 pointers or 0.0 floats are >represented on some crazy systems.) ANSI, are you listening? I think that *not* zeroing out memory should be the default. My reasons are as follows: 1) Zeroing is infrequently needed and seldom even helpful. 2) Any values needing initialization can be initialized by the constructor for the object. 3) Frequently the overhead for the constructor performing the initialization is little more than that required for initialization at allocation time. 4) If initialization needs to be done field by field then extra code is added to the constructor to perform that initialization. This would be code which is often not needed. 5) Initialization of objects at allocation time adds time to the allocation of *every* object when it is needed for only a few objects. 6) For large objects such as buffers in the megabyte range initialization time can result in visible delays while buffers are allocated. For such buffers initialization is usually not needed. 7) In addition to global operator new an objects operator new can be overloaded to initialize the memory if needed In summary it is my opinion (not that my opinion counts) that initialization of object upon allocation is of dubious benefit, and so is a waste of time and possibly code. I would prefer to see the spec remain the same. ANSI, are you listening? -- Dave Scidmore, Heurikon Corp. dave.scidmore@heurikon.com