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,c63aa81a67eceb8f X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Ragged Array Proposal Date: 1999/09/23 Message-ID: <37EA4E91.1D4D1FC@averstar.com>#1/1 X-Deja-AN: 528684472 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <37e7c08e@eeyore.callnetuk.com> <7satei$e2q$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-09-23T00:00:00+00:00 List-Id: Ray Blaak wrote: > > Ted Dennison writes: > > Also for your example you say "the various ways of doing the equivalent > > thing in Ada 95 are all unappealing." I but I can do the equivalent > > thing in Ada 95 in only 2 more lines of code: > > > > type Command_String_Ptr is access all String; > > for Command_String_Ptr'Storage_Size use 1024; > > > > type Command is (Cut, Copy, Paste, ...); > > > > Labels: constant array (Command) of Command_String_Ptr := > > (Cut => new String'("Cu&t"), > > Copy => new String'("&Copy"), > > > > Paste => new String'("&Paste"), > > ...); > > The problem with this approach is that the data is duplicated. It is both in > the static data area of the program (i.e. the string constants), and in the > heap. If you change Command_String_Ptr to be "access constant String;" then the recommended implementation does *not* duplicate the static data. It is link-time allocated and initialized. This might vary by compiler, but anything having to do with link-time initialization is an "optimization," so that is true even for static constants. I know at least that the Aonix and Green Hills Ada 95 compilers statically allocate and initialize allocators for access-to-constant types. I haven't checked GNAT. > In Ada95, to avoid duplicating the data, the approach is tedious (i.e. having > an aliased constant for each string, and assigning their 'Access values into > the array). As mentioned above, that is not necessary if the type is access-to-constant (which it must be if you are using 'Access on aliased constants). Take a look at the generated code for new String'("xxx") when the type is access-to-constant. It should not involve any run-time code (presuming the implementation advice was followed by the compiler implementor). > > -- > Cheers, The Rhythm is around me, > The Rhythm has control. > Ray Blaak The Rhythm is inside me, > blaak@infomatch.com The Rhythm has my soul. -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA