Newsgroups: alt.lang.design,comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.lang.ada
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!news.bu.edu!inmet!dsd!bobduff
From: bobduff@dsd.camb.inmet.com (Bob Duff)
Subject: Re: Reference Counting (was Re: Searching Method for Incremental Garbage Collection)
Message-ID: <D0x53v.FxE@inmet.camb.inmet.com>
Sender: news@inmet.camb.inmet.com
Organization: Intermetrics, Inc.
References: <hbakerD08qGF.4qM@netcom.com> <D0KDGE.31F@inmet.camb.inmet.com> <gmckee.1137578003A@news-2.csn.net> <hbakerD0oM3E.7s3@netcom.com>
Date: Fri, 16 Dec 1994 19:35:54 GMT
Lines: 23
Xref: glinda.oz.cs.cmu.edu comp.lang.c:121118 comp.lang.c++:103705 comp.lang.lisp:16081 comp.lang.ada:24771

In article <hbakerD0oM3E.7s3@netcom.com>,
Henry G. Baker <hbaker@netcom.com> wrote:
>Another common example is a function that returns an object of
>arbitrary size.  You don't know how much space to allocate for it
>on the stack, and if you simply redefine the stack frame to include
>the object (which was stack-allocated by the called function), then
>you may waste huge amounts of space on the stack.  So you're better
>off allocating it in a heap, but remembering that you have only
>one pointer to it.

Some Ada compilers allocate those things on the heap.  However, others
(most, I believe) allocate those things on the stack.  When the function
returns, the result object is copied from wherever it is down to where
it belongs.  There are numerous complicated optimizations that can be
done to avoid the copying in many cases.  Some compilers use the normal
run-time stack, whereas others have a secondary stack for these kinds of
things, but either way, the principle is the same.

- Bob
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)
