comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: warning: Storage_Error will be raised at run-time
Date: 1997/12/15
Date: 1997-12-15T00:00:00+00:00	[thread overview]
Message-ID: <dewar.882235377@merv> (raw)
In-Reply-To: 97121515433681@psavax.pwfl.com


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!





  parent reply	other threads:[~1997-12-15  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-15  0:00 warning: Storage_Error will be raised at run-time Marin David Condic, 561.796.8997, M/S 731-96
1997-12-15  0:00 ` Tucker Taft
1997-12-15  0:00 ` Robert Dewar [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-12-16  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-16  0:00 ` Robert Dewar
1997-12-16  0:00 ` Tucker Taft
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox