comp.lang.ada
 help / color / mirror / Atom feed
From: gpriv@axonx.com
Subject: Re: Prohibiting dynamic allocation for the given type
Date: Tue, 18 Mar 2008 20:06:45 -0700 (PDT)
Date: 2008-03-18T20:06:45-07:00	[thread overview]
Message-ID: <bbf57cd3-2b37-4a48-8fad-d8ce72968957@e39g2000hsf.googlegroups.com> (raw)
In-Reply-To: 83335709-e099-416b-9967-5ab6aa0aea11@i12g2000prf.googlegroups.com

On Mar 18, 5:30 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> Is it possible to "prohibit" dynamic allocation for the given type?
>
> Let's suppose that I have a type which instances make sense only on
> the stack.

Ada is high level language and stack is implementation specific
entity. ARM does not mention how the local objects are allocated (it
simply irrelevant).  In fact, GNAT uses two stacks for different type
of objects but users don't have to know these details.

> I want to prohibit users from dynamically allocating
> instances of this type so that they don't get into troubles.
> Preferably at compile-time.

What's wrong with good old comments atop of type declaration. Like
some beverages have: "for most enjoyment serve chilled" or "for best
performance avoid heap allocation".

Don't know if it's ever possible to do it during compile, nothings
comes to my mind. But if you insist you may do run-time check by
defining custom Storage_Pool pool for your object and raising
exception from Allocate method. See ARM 3.11 for details.

G.

>
> My understanding is that it cannot be done (allocation is not
> considered to be a type's operation and there is no way to "hide" it
> from users - as is possible in C++), but I would like to have it
> confirmed.
>
> --
> Maciej Sobczak *www.msobczak.com*www.inspirel.com





  reply	other threads:[~2008-03-19  3:06 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 [this message]
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
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