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,903f8471df09a778 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: warning: Storage_Error will be raised at run-time Date: 1997/12/15 Message-ID: #1/1 X-Deja-AN: 298546029 References: <97121515433681@psavax.pwfl.com> X-Complaints-To: usenet@news.nyu.edu X-Trace: news.nyu.edu 882235659 2524 (None) 128.122.140.58 Organization: New York University Newsgroups: comp.lang.ada Date: 1997-12-15T00:00:00+00:00 List-Id: Marin says << My best guess is that the implementation takes a look at the "(Size : Natural := 0)" part and decides that it needs to allocate 1..Natural'Last bytes for the Table field of every object of type Variant_Type. I can see how this would make it simple to handle assignments to objects of type Variant_Type since they would have already allocated memory for the worst case scenario. This seems like a bad implementation choice in that, while it may be very fast, doesn't allow the user much leeway. (This seems to be the case even when you declare an object with a fixed discriminant and an initial expression. It still wants to allocate for the worst case, presumably in anticipation of reassignment to the object. Or is it something else altogether?) >> This is an old discussion, and one on which compilers have historically disagreed. There are two viewpoints: 1. Implicit heap allocation is to be avoided, if you want to handle variable length objects using pointers and dynamic allocation, it should be done exoplicitly in the code. 2. It is fine to use implicit heap allocations and implicit pointers. Many Ada compilers have preferred approach 1 in the past (e.g. DEC Ada), and that is the approach that GNAT takes, so the maximum space is always allocated statically. I believe that the Intermetrics compiler takes the same approach. Using dynamic allocation can result in some nasty implementation problems, since to do it right, you need to have non-contiguous representations. Alsys used dynamic allocation on only one level, so you could declare these mutant objects at the outer level, but you could not have arrays of them, because for arrays they allocated the maximum size and restricted it to a small value. RR tried to do the dynmaic allocation fully resulting in non=contiguous objects, but at least at one point, would output warnings that storage leaks could result. I think it is clear that the maximum space allocation is the right choice. If you want dynamic allocation, and poiners, use NEW and ACCESS!