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-Thread: 103376,ec2a500cce3658c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada References: Subject: Re: Memory leak - What the ...? Date: Wed, 13 Oct 2004 10:45:38 -0400 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: <416d3ca6$0$36214$39cecf19@news.twtelecom.net> Organization: Time-Warner Telecom NNTP-Posting-Date: 13 Oct 2004 14:33:10 GMT NNTP-Posting-Host: 9ec9fb12.news.twtelecom.net X-Trace: DXC=K9HcSM^MhFZG[n\L2_@9VQC_A=>8kQj6]=_1NR_H?JP]^:T@Q3 "Stephen Leake" wrote in message news:mailman.304.1097670377.390.comp.lang.ada@ada-france.org... > Surely any halfway decent compiler would optimize these to be the > same? > > Hmm. Perhaps declaring an object requires calling Initialize, Adjust, > and Finalize, unless the compiler can _prove_ those subprograms have > no side-effects, which it probably can't do. Is that your point? Something like that. If I have this: function Op return CT is --some controlled type O : CT; begin O.X := ...; return O; end; then local controlled object O must be Initialize'd when it is declared, and Finalize'd when the scope of its declaration ends. If you do it this way: function Op return CT is begin return CT'(Controlled with X => ...); end; then the compiler can probably build the return value in place: declare O : CT := Op; begin This is similar to the return-value optimization in C++. As another example, the AI-302 set functions Union, Intersection, etc, are implemented this way: function Union (L, R : Set) return Set is Tree : Tree_Type; --ordered set uses red-black tree (a type which isn't controlled) begin ... -- build Tree return Set'(Controlled with Tree); end;