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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f868292008c639ce X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: Java vs. Ada - strings (was: C vs. Ada - strings) Date: 2000/06/04 Message-ID: <3939F090.5080CD5E@earthlink.net>#1/1 X-Deja-AN: 630816970 Content-Transfer-Encoding: 7bit References: <390F0D93.F835FAD9@ftw.rsc.raytheon.com> <8en5o9$ihe$1@nnrp1.deja.com> <8eonos$e70$1@wanadoo.fr> <1fIU4.4668$Rx3.250161@typhoon.nyroc.rr.com> <3924B730.AFB52C1C@acenet.com.au> <39394E0B.75BD479C@telepath.com> X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 960098306 63.24.55.119 (Sat, 03 Jun 2000 22:58:26 PDT) Organization: The MITRE Corporation MIME-Version: 1.0 NNTP-Posting-Date: Sat, 03 Jun 2000 22:58:26 PDT Newsgroups: comp.lang.ada Date: 2000-06-04T00:00:00+00:00 List-Id: Ted Dennison wrote: > > Pete wrote: > > > I see your point. But suppose in Java, I have > > Srting ar[] = new String[] { "have", "a", "good", "day" }; > > // assume some processing. > > ar[2] = "junk"; ... > I've never done this myself because in 11 years of Ada work I've never had a > much need for ragged string arrays. That's probably why Ada doesn't come with a > type for them. :-) Actually, there are uses for ragged string arrays, and that is one reason why Ada.Strings.Bounded and Ada.Strings.Unbounded were added to Ada 95: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; ... type String_Array is array(Natural range <>) of Unbounded_String; function "+"(Right: String) return Unbounded_String renames To_Unbounded_String; -- You probably want to do this anyway, not just for the conditions of contest. Ar: String_Array := (+"have",+"a",+"good",+"day"); ... Ar(2) := +"junk"; ... The Ada code generated may use the heap, or it may get clever. In either case you don't need to worry about storage leaks. (RM A.4.5(88)) Of course, in Java, you don't need to worry about a storage leak on the assignment either, since it will eventually get garbage collected. If you use Ada.Strings.Bounded instead, you should expect the compiler to avoid the heap.(RM A.4.4(106))