comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Is this actually possible?
Date: Thu, 12 Dec 2019 11:26:05 +0200
Date: 2019-12-12T11:26:05+02:00	[thread overview]
Message-ID: <h5efddF2clU1@mid.individual.net> (raw)
In-Reply-To: <qss70r$n88$1@franka.jacob-sparre.dk>

On 2019-12-12 4:00, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:qsrncj$u95$1@gioia.aioe.org...
>> On 2019-12-11 22:12, Lucretia wrote:
> ...
>> Why? You must know all variants in order to compute the array element
>> size. In Ada you cannot have it either:
>>
>>     type Not_an_Array is array (Positive range <>) of T'Class;
>>
>> This is illegal.
> 
> This is the purpose of the Bounded_Indefinite_Holders, because this is a
> useful thing to do sometimes.
> 
>      package My_Holders is new Ada.Containers.Bounded_Indefinite_Holders
> (T'Class, 100);
> 
>      type An_Array is array (Positive range <>) of My_Holders.Holder;
> 
> Here, a Holder will hold up to 100 storage units. If some extension of
> T'Class is bigger than that, setting the holder to a value of that extension
> raises Program_Error. (As with most checks, this one can be suppressed, and
> if it would fail and is suppressed, the program is erroneous - presumably
> some other object memory would be overwritten. So don't do that. ;-)
> 
> This is probably one of the best (and simplest) ideas of Ada 202x. Thanks to
> Niklas Holsti for the original idea (although I think the actual resulting
> package isn't much like Niklas' original idea).

Thanks for the credit, Randy.

I wanted a way to statically allocate a "max size" for class-wide 
objects, just as many compilers currently use an "allocate max size" for 
variant records with a default discriminant. My suggestion would also 
have needed the ability to change the tag of such a class-wide object, 
just as the discriminant of a variant-record object can be changed by 
assigning to the whole object.

The wise heads of the ARG introduced the Bounded_Indefinite_Holder, 
giving just this effect: a bounded size, allowing static storage 
allocation, but also letting me change the tag by replacing the object 
being held with another object.

My only worry about the present solution is if there is a lot of memory 
overhead in the Bounded_Indefinite_Holder. I don't see why there should 
be, but I guess I'll have to wait for an implementation to find out.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

  reply	other threads:[~2019-12-12  9:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11 16:43 Is this actually possible? Lucretia
2019-12-11 17:38 ` Dmitry A. Kazakov
2019-12-11 17:54   ` Lucretia
2019-12-11 19:55     ` Randy Brukardt
2019-12-11 19:58     ` Dmitry A. Kazakov
2019-12-11 21:12       ` Lucretia
2019-12-11 21:34         ` Dmitry A. Kazakov
2019-12-12  2:00           ` Randy Brukardt
2019-12-12  9:26             ` Niklas Holsti [this message]
2020-04-08 16:10             ` Alejandro R. Mosteo
2019-12-12 10:17           ` Lucretia
2019-12-12 14:32             ` Dmitry A. Kazakov
2019-12-12 15:14               ` Lucretia
2019-12-12 15:15                 ` Lucretia
2019-12-12 18:24                   ` Dmitry A. Kazakov
2019-12-12 18:30                     ` Lucretia
2019-12-12 19:09                       ` Dmitry A. Kazakov
2019-12-12 20:54                         ` Lucretia
2019-12-12 21:12                           ` Dmitry A. Kazakov
2019-12-13 11:11                             ` Lucretia
2019-12-11 19:59 ` Randy Brukardt
replies disabled

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