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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,147f221051e5a63d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!npeer03.iad!news.highwinds-media.com!cycny01.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc04.POSTED!c44d10bf!not-for-mail From: "Bob Klungle" Newsgroups: comp.lang.ada References: <4ddef8bf-b5b1-4d7e-b75b-386cd6c8402c@l17g2000pri.googlegroups.com> <482E8A9D.5040401@obry.net> Subject: Re: memory management in Ada: tedious without GC? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 Message-ID: <8ACXj.3769$IK5.622@trnddc04> Date: Sat, 17 May 2008 15:11:00 GMT NNTP-Posting-Host: 71.177.102.122 X-Complaints-To: abuse@verizon.net X-Trace: trnddc04 1211037060 71.177.102.122 (Sat, 17 May 2008 11:11:00 EDT) NNTP-Posting-Date: Sat, 17 May 2008 11:11:00 EDT Xref: g2news1.google.com comp.lang.ada:159 Date: 2008-05-17T15:11:00+00:00 List-Id: "Pascal Obry" wrote in message news:482E8A9D.5040401@obry.net... > jhc0033@gmail.com a �crit : >> Did I misunderstand? > > You have already received a bunch of excellent answers. I'd like to point > out that in Ada you have less need for dynamically allocated memory. Ada > supports unconstraint types. Objects of such types when declared can be > "allocated" on the stack and passed around (no heap usage). A simple > example: > > type Vector is (Positive range <>) of Float; > > function Norm (V : in Vector) return Float; > > ... > > declare > V : Vector (1 .. 100); > R : Float; > begin > R := Norm (V); > ... > > Not a single memory allocation. In C/C++ you'll need to dynamically > allocate V on the heap, and then worry about freeing this memory. > > Pascal. Actually, the same construct exists in c/c++. Stack frame allocation only needs a block to allow object definitions (c++ does it almost anywhere). To whit: #include int main(void) { int x = 3; int y = 7; int z = 2; printf("x, y, z: %0d, %0d, %0d\n", x, y, z); { int w = 9; printf("x, y, z, w: %0d, %0d, %0d, %0d\n", x, y, z, w); } } x, y, z: 3, 7, 2 x, y, z, w: 3, 7, 2, 9