From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,591cbead201d7f34 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!e39g2000hsf.googlegroups.com!not-for-mail From: gpriv@axonx.com Newsgroups: comp.lang.ada Subject: Re: Prohibiting dynamic allocation for the given type Date: Tue, 18 Mar 2008 20:06:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <83335709-e099-416b-9967-5ab6aa0aea11@i12g2000prf.googlegroups.com> NNTP-Posting-Host: 69.250.188.114 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1205896005 30556 127.0.0.1 (19 Mar 2008 03:06:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 19 Mar 2008 03:06:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e39g2000hsf.googlegroups.com; posting-host=69.250.188.114; posting-account=YaY8rAoAAAAAnFXOECY3BGVJsrvFJCgy User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20476 Date: 2008-03-18T20:06:45-07:00 List-Id: On Mar 18, 5:30 pm, Maciej Sobczak 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