From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b99897135d6631cc X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!news3.optonline.net!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed2.sea.pnap.net!newsfeed.pnap.net!brmea-news-1.sun.com!news1brm.central.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: memory management and productivity Date: 22 Jun 2004 09:58:09 +0200 Organization: Sun Microsystems Message-ID: References: <40d15023$1_1@baen1673807.greenlnk.net> <2jnh22F12nvieU2@uni-berlin.de> NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1087891089 29351 129.159.112.195 (22 Jun 2004 07:58:09 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 22 Jun 2004 07:58:09 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:1766 Date: 2004-06-22T07:58:09+00:00 List-Id: >>>>> "FJL" == Frank J Lhota writes: FJL> "Ole-Hjalmar Kristensen" FJL> wrote in message FJL> news:wvbrsmcp2uqd.fsf@europa1.Norway.Sun.COM... >> > Russ wrote: >> Yes, *IF* it has been allocated with new. FJL> In C++, all memory allocation / deallocation should be done using the new / FJL> delete operators. This is true even for pointers to classes that do not have FJL> constructors or destructors. This is because classes often have default FJL> constructor / destructor actions that need to be performed for the object to FJL> be usable. For example, if the class has any virtual methods, then "jump FJL> table" must be set up. Also, if any field / sub-field / sub-sub-field has a FJL> constructor / destructor, then this constructor / destructor cannot be FJL> ignored. Yes, I agree. I was thinking about stack-allocated objects, where the destructor is called automatically for you upon exit of the varaible's scope. FJL> The safe way to change the memory management algorithms for a given C++ FJL> class is to define new / delete operators for that class. This will permit FJL> the user-defined algorithms for allocation / deallocation to be used for the FJL> class without interfering with constructor / destructor actions. This is the FJL> C++ equivalent of the Ada "for Name'Storage_Pool use ...;" clause. >> This is exactly the same as C++. I would say that Ada and C++ are >> more or less on equal footing when it comes to garbage collection in >> practice. FJL> I agree. It would be more accurate to say that in both Ada and C++, the FJL> tools are there to implement your types with GC. Yes, that would be more accurate, although conservative collectors like Boehm's would probably work with both languages. -- C++: The power, elegance and simplicity of a hand grenade.