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,e5eb8ca5dcea2827 X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Ada OO Mechanism Date: 1999/06/08 Message-ID: <375D9A3D.E1CCCC63@averstar.com>#1/1 X-Deja-AN: 487260641 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <7i05aq$rgl$1@news.orbitworld.net> <7i17gj$1u1k@news2.newsguy.com> <7icgkg$k4q$1@nnrp1.deja.com> <3749E9EC.2842436A@aasaa.ofe.org> <7id2eo$fag@drn.newsguy.com> <3749FF7D.F17CE16A@aasaa.ofe.org> <374AC676.F7AE0772@lmco.com> <7ieuja$5v9@news1.newsguy.com> <7ifd6l$bmf@sjx-ixn1.ix.netcom.com> <1999Jun8.151014.1@eisner> Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-06-08T00:00:00+00:00 List-Id: Hyman Rosen wrote: > > kilgallen@eisner.decus.org (Larry Kilgallen) writes: > > The fact that GNAT allocates it in one place does not mean all compilers > > will do it in the same place. Is your question specifically "how does > > GNAT do this ?" ? > > I am trying to understand the mechanism behind T'Class. I have been told > that the size of such variables is determined at run-time, and also that > the heap is not required for such variables. > > So, to anyone, if you don't mind taking the time to explain, how does > implement this? Several compilers use what is called a "secondary stack" (or a "data stack"), as distinct from the "primary stack" (or "control stack"). The secondary stack is generally managed in a mark/release manner. There is one per task. On entry to a subprogram or block the secondary stack is marked, and prior to exit, the secondary stack is released. In the interim objects of run-time-determined size may be allocated as needed. A pointer to the object is generally stored on the primary stack. For functions that return objects of size unknown to the caller, the function creates the object on (or copies the object to) the secondary stack, and then returns from the function *without* releasing the secondary stack. The caller takes care of releasing the secondary stack once they are through with using the returned object. There are other compilers that use "local" heaps, or other heap-based mechanisms. They all still typically use some kind of mark/release, though it may be a mark/release on a linked-list of objects, rather than on a secondary stack. > > Also, I stated in an earlier message that I thought not allowing T'Class > variables in records was not orthogonal, but understandable in light of > the above. Now, suppose I need a function that returns a pair of values, > one of which is a T'Class and the other a boolean. Is there a way to do > this? I can't return a record containing the pair, because I can't have > such a record. I assume that a procedure with a pair of out parameters > won't work, because the T'Class variable which receives the output must > be initialized when declared, and then its tag can't change. So, is there > a way? No. Once you need to combine a class-wide value with something else, you will have to use the heap explicitly. (I suppose you could add an "access Boolean" parameter to a function if you wanted to return a Boolean as well as a class-wide value.) As pointed out by Markus Kuhn, Ada goes one (important, in my mind) step beyond C/C++ by providing built-in, safe support for objects whose size is not known at compile-time. However this support is not completely flexible -- it is generally restricted to cases where the size is known at the time when the object is declared. Explicit use of the heap is the fallback approach when you need more flexibility than is directly supported. -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA