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,fea5f9c57f8bf287 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-20 10:39:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.direct.ca!look.ca!wn1feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc06-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3BD1B6F3.F90883D7@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Discriminants constraining unconstrained array types References: <87g08e9urn.fsf@chiark.greenend.org.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sat, 20 Oct 2001 17:39:43 GMT NNTP-Posting-Host: 12.86.32.57 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 1003599583 12.86.32.57 (Sat, 20 Oct 2001 17:39:43 GMT) NNTP-Posting-Date: Sat, 20 Oct 2001 17:39:43 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:14972 Date: 2001-10-20T17:39:43+00:00 List-Id: Matthew Woodcraft wrote: > > The following rule appears in the GNAT coding style guide: > > | Do not declare discriminated record types where the discriminant is > | used for constraining an unconstrained array type. (Discriminated > | records for a variant part are allowed.) > > Does anyone know a reason to avoid this feature of the language in > general, or is it more likely that there's just some issue with the > runtime or bootstrap behaviour which makes it inadvisable to use in the > compiler itself? I was not involved in the team that wrote this guideline. I can explain some of the problems with declaring discriminated record types used for constraining unconstrained array types. The first problems is memory usage. Take the following example: type Unconstrained_Type is array(Positive range <>) of Integer; type Inadvised_Record_Type (Max : Positive) is record Buffer : Unconstrained_Type(1..Max); end record; The compiler must identify the size of Inadvised_Record_Type. The problem arises because the array constraints are determined at run-time and not at compile-time. The only vaguely reasonable option for the compiler is to set Buffer'Size equal to Positive'Last * Integer'Size. This means that you will be wasting large amounts of memory for every instance of Inadvised_Record_Type. This also causes problems when you want to write an instance of Inadvised_Record_Type to a stream. The size written to the stream will be the entire buffer size, not simply Buffer'Length Integer, plus another Integer for the Max discriminant. If you are sending this stream representation across a communication link you will get very poor throughput due to the excessive number of extra Integer data elements sent corresponding to the wasted buffer space. The point is that individual data elements in a record type should be of a fixed or constrained size. Jim Rogers Colorado Springs, Colorado USA