comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Proposal: Auto-allocation of Indefinite Objects
Date: Sat, 4 Apr 2020 12:54:44 +0200
Date: 2020-04-04T12:54:44+02:00	[thread overview]
Message-ID: <r69p1k$tei$1@dont-email.me> (raw)
In-Reply-To: <7d0c6237-da84-4d48-8aa4-764b747975be@googlegroups.com>

On 4/4/20 1:45 AM, Stephen Leake wrote:
> 
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> 
> declare
>     Foo : Unbounded_String; -- empty
> begin
>     Foo := To_Unbounded ("hi"); -- allocated on the heap
>     Foo := Foo & To_Unbounded ("bye"); -- allocation grows

Foo := Foo & "bye";

Those should be To_Unbounded_String;

For an issue related to the OP's idea, consider

with System;

procedure Boom is
    type Very_Large_Item is ...;
    type Very_Large_Index is mod System.Max_Binary_Modulus;
    type Very_Large_List is array (Very_Large_Index range <>) of Very_Large_Item;

    Last : constant := ...;

    List : Very_Large_List (0 .. Last);
begin -- Boom
    ... -- Do some thing useful with List
end Boom;

There exists a value N > 0 such that Last = N works and Last = N + 1 results in 
Storage_Error. The actual value of N may vary depending on the compiler, target, 
and the actual machine on which the program is executed.

If you want to handle a List with Last > N, you have to make it an access to 
Very_Large_List unless you care where it is allocated. There is still a value M 
which will result in Storage_Error, but on most machines where you'd try to 
process such a large object, M >> N because on such machines the heap is much 
larger than the stack. Implicit dereferencing makes this change less painful 
than it would be without implicit dereferencing, but there are still usually 
places where explicit dereferencing will be needed, so there is still some pain 
involved even though you don't care where the object is allocated.

It would be nice if there were a compiler option where objects that don't fit on 
the stack would be automatically allocated on the heap, and automatically 
deallocated when they go out of scope.

Similar arguments can be made for a compiler option where all numeric types 
would be accepted, with some implemented in terms of the compiler's ability to 
calculate static expressions exactly, rather than the user having to switch from 
a numeric type to an unbounded-number pkg. This has the added value that such 
pkgs usually lose the automated checks that numeric types have.

All of these issues have been around for some time, and the ARG is aware of them 
and has chosen to take no action. That seems unlikely to change.

-- 
Jeff Carter
"I'm a vicious jungle beast!"
Play It Again, Sam
131

  reply	other threads:[~2020-04-04 10:54 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-03 22:48 Proposal: Auto-allocation of Indefinite Objects Stephen Davies
2020-04-03 23:45 ` Stephen Leake
2020-04-04 10:54   ` Jeffrey R. Carter [this message]
2020-04-04 20:55     ` Stephen Davies
2020-04-04  8:31 ` Dmitry A. Kazakov
2020-07-27  7:47 ` Yannick Moy
2020-07-27  9:21   ` J-P. Rosen
2020-07-27  9:49     ` Dmitry A. Kazakov
2020-07-27 17:48   ` Brian Drummond
2020-07-27 20:02     ` Dmitry A. Kazakov
2020-07-28 14:28       ` Brian Drummond
2020-07-28 14:59         ` Dmitry A. Kazakov
2020-07-29 15:33           ` Brian Drummond
2020-07-29 16:20             ` Dmitry A. Kazakov
2020-07-30 13:37               ` Stephen Davies
2020-07-30 14:23                 ` Dmitry A. Kazakov
2020-07-30 17:04               ` Brian Drummond
2020-07-30 18:28                 ` Dmitry A. Kazakov
2020-08-10  0:39                   ` Randy Brukardt
2020-08-10  8:57                     ` Dmitry A. Kazakov
2020-08-20  0:10                       ` Randy Brukardt
2020-08-20 17:49                         ` Dmitry A. Kazakov
2020-08-20 20:19                           ` Dennis Lee Bieber
2020-08-20 23:33                             ` Randy Brukardt
2020-08-21  6:45                               ` Dmitry A. Kazakov
2020-08-23  4:52                                 ` Randy Brukardt
2020-08-23 12:28                                   ` Dmitry A. Kazakov
2020-08-20 23:30                           ` Randy Brukardt
2020-08-21  6:46                             ` Dmitry A. Kazakov
2020-08-23  4:48                               ` Randy Brukardt
2020-08-23 12:29                                 ` Dmitry A. Kazakov
2020-08-10  0:31               ` Randy Brukardt
2020-08-10  8:58                 ` Dmitry A. Kazakov
2020-08-20  0:13                   ` Randy Brukardt
2020-08-20 17:49                     ` Dmitry A. Kazakov
2020-08-20 23:25                       ` Randy Brukardt
2020-08-21  7:08                         ` Dmitry A. Kazakov
2020-08-23  5:03                           ` Randy Brukardt
2020-08-23 12:28                             ` Dmitry A. Kazakov
2020-07-27 20:31     ` Jeffrey R. Carter
2020-07-31  9:25 ` Stephen Davies
2020-07-31 10:20   ` Dmitry A. Kazakov
2020-08-01 11:22     ` Stephen Davies
2020-08-01 12:58       ` Dmitry A. Kazakov
2020-08-01 20:35         ` Stephen Davies
2020-08-01 20:56           ` Dmitry A. Kazakov
2020-09-03  4:30 ` linda white
replies disabled

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