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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ed6a891101ff4e06 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Freeing Pointers to classwide types Date: 1998/10/11 Message-ID: #1/1 X-Deja-AN: 399955131 Sender: matt@mheaney.ni.net References: <1ftmFTC69GA.191@samson.airnet.net> <361E65A8.36082B5D@icon.fi> <362081E9.5CF38122@icon.fi> NNTP-Posting-Date: Sun, 11 Oct 1998 08:47:31 PDT Newsgroups: comp.lang.ada Date: 1998-10-11T00:00:00+00:00 List-Id: Niklas Holsti writes: > On the other hand, it seems that GNAT (in WebAda) lets one specify > a positive Storage_Size for an access type to a descendant of the > type T, so it would seem possible for clients to use "new" for > descendant types. Doesn't this break your approach? There's nothing that prevents someone from declaring their own access type. What I was trying to do was say to the user the memory allocation and deallocation are hidden behind primitive operations provided by the abstraction. Somehow you have to tell the client that he isn't supposed to call new and Unchecked_Deallocation himself. It has been my experience that compilers obey you when you set the storage size to 0. If a client forgets, and he does call allocator new, then he'll get storage error. This isn't as nice as detecting the error at compile time, but it gets the job done. (Although a good compiler will tell you at compile-time that the allocation will raise Storage_Error.) I follow the philosophy that allocator new (and Unchecked_Deallocation) are operations used only to _implement_ higher-level operations provided by an abstraction. It's not unlike an array or a list. Those data structures are primitive, in the sense that they should only be used to implement higher-level data structures. A client should never directly use a list as a data structure.