comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Prohibiting dynamic allocation for the given type
Date: Wed, 19 Mar 2008 18:08:34 -0500
Date: 2008-03-19T18:08:34-05:00	[thread overview]
Message-ID: <frs6e3$fh0$1@jacob-sparre.dk> (raw)
In-Reply-To: 47E11F35.5000900@obry.net

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1784 bytes --]

"Pascal Obry" <pascal@obry.net> wrote in message
news:47E11F35.5000900@obry.net...
> Maciej Sobczak a �crit :
> > Is it possible to "prohibit" dynamic allocation for the given type?
>
> Just a quick idea... What about using a storage pool which raises a
> program_error when using it. Then apply this storage pool to the type
> where you want to forbid dynamic allocation. Shouldn't something like
> this work?

If this did work (it doesn't, as mentioned by many), it would be easier to
simply specify 'Storage_Pool to be 0, which prohibits allocation.

But the whole idea seems dubious to me. Most types (ADTs) ought to be
constructed so that the client can use them in whatever way they want - that
is, they shouldn't only work in a single way. (Non-ADT types aren't really
interesting, as they usually are hidden in a package body, or are some sort
of discrete type for which nothing very interesting can happen.)

Moreover, for types where lifetime matters (like types with automatically
released locks), *how* the object is created is not really relevant. An
object allocated from a local access type, or even one allocated from a
global access type that is later freed with Unchecked_Deallocation both
would meet the requirement of a limited lifetime.

Which is all to say that Ada doesn't really have a way to express lifetime
of types (at least of ADT types), and thus you have to fall back on usage
rules as part of the documentation of the ADT. As someone else mentioned,
someone who uses a lock in a global context doesn't understand the purpose
of the type very well...

More generally, there are always going to be things that cannot be
statically expressed in a programming language. This seems like one of them
for Ada.

                                   Randy.





  reply	other threads:[~2008-03-19 23:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-18 21:30 Prohibiting dynamic allocation for the given type Maciej Sobczak
2008-03-19  3:06 ` gpriv
2008-03-19  8:24   ` Maciej Sobczak
2008-03-19 11:31     ` Georg Bauhaus
2008-03-19 13:13     ` gpriv
2008-03-19 13:54       ` Maciej Sobczak
2008-03-19 16:37     ` Eric Hughes
2008-03-20  0:48       ` Robert A Duff
2008-03-20 21:35         ` Eric Hughes
2008-03-19 22:17     ` Georg Bauhaus
2008-03-19 23:40       ` gpriv
2008-03-20 21:11       ` Maciej Sobczak
2008-03-19 14:38   ` Adam Beneschan
2008-03-19 15:43     ` gpriv
2008-03-19 14:12 ` Pascal Obry
2008-03-19 23:08   ` Randy Brukardt [this message]
2008-03-20 20:26     ` Simon Wright
2008-03-20 22:03       ` Eric Hughes
2008-03-21  1:04         ` Randy Brukardt
2008-03-20  0:43 ` Robert A Duff
replies disabled

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