Previous mail
Next mail
Formatted
Overview 10 days
Subject
Date
Thread
Author
From gpc-owner+M8013@gnu.de Wed Sep 03 10:07:43 2008 Received: from localhost ([127.0.0.1] helo=gnu.de) by ngc224.gerwinski.de with smtp (Exim 4.50 #1 (Debian)) id 1KanNg-0007Pz-7E; Wed, 03 Sep 2008 10:06:24 +0200 Received: from smtp-out.vodafone.nl ([195.232.199.126] helo=smtp.vodafone.nl) by ngc224.gerwinski.de with esmtp (Exim 4.50 #1 (Debian)) id 1KanNU-0007OP-Sz for <gpc@gnu.de>; Wed, 03 Sep 2008 10:06:21 +0200 Received: from conversion-daemon.vfnlw44s.vfnl.dc-ratingen.de by vfnlw44s.vfnl.dc-ratingen.de (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) id <0K6M00F0103N1F00@vfnlw44s.vfnl.dc-ratingen.de> (original mail from gpc@microbizz.nl) for gpc@gnu.de; Wed, 03 Sep 2008 09:43:52 +0200 (CEST) Received: from [192.168.1.110] ([77.204.242.129]) by vfnlw44s.vfnl.dc-ratingen.de (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0K6M005IM051VZ90@vfnlw44s.vfnl.dc-ratingen.de> for gpc@gnu.de; Wed, 03 Sep 2008 09:43:51 +0200 (CEST) Date: Wed, 03 Sep 2008 09:43:47 +0200 From: Adriaan van Os <gpc@microbizz.nl> Subject: Re: Garbage Collection In-reply-to: <48B977A4.7080507@umich.edu> To: gpc@gnu.de Message-id: <48BE4033.4040200@microbizz.nl> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT References: <48B977A4.7080507@umich.edu> User-Agent: Thunderbird 1.5.0.4 (Macintosh/20060516) X-Spam-Score: 0.1 (/) Precedence: bulk Sender: gpc-owner@gnu.de Prof. Harley Flanders wrote: > Suppose I have defined > > type Vec = array[1..1000] of Extended; // 10,000 bytes Not always 10,000 bytes, it depends on how many bytes an Extended has, e.g. on some platforms 8 bytes, like a double, or 16 bytes like a longdouble. > var A, B, C, D: Vec; > > function Sum(const A, B: Vec): Vec; > > In the assignment > > D := Sum(Sum(A, B), C); > > there is an intermediate result Sum(A, B), going to an unnamed temporary > vector. The intermediate vector will be placed on the stack. > Does garbage collection pick up that space? The space for the temporary vector is automatically freed, but the term "garbage collection" <http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)> usually refers to automatic heap management methods, not to call stack unwinding <http://en.wikipedia.org/wiki/Call_stack>. > Similar question with > > operator + (const A, B: Vec) C: Vec; > > D := (A+B)+C; > > More complicated: Delphi mode, so I have "Result" available > > var Zero: Vec; // Zero[J] = 0 for all J > > function Foo(A: Vec; N: Word): Vec; > > var B: Vec; > > begin > if N = 0 then Result := Zero > else if Odd(N) then > Result := A + Foo(A, N - 1) > else begin > B := (Foo(A, N div 2) > Result := B + B; > end; > end; // Foo > > Garbage collection handles this correctly? See the above answer. > Whatever the answers, how do I PROVE them by measuring stack, heap, or > whatever? You don't need to worry about deallocation of temporary space for function results. However, ask yourself if there is enough stack space to put "big" function results on the stack, especially if you are also using recursion. That depends. The alternative is to use a VAR parameter for the result of the calculation (but be aware that a local variable will also be allocated on the call stack). Regards, Adriaan van Os
Previous mail
Next mail
Formatted
Overview 10 days
Subject
Date
Thread
Author
| Author | Subject | Date |
|---|---|---|
| Prof. Harley Flanders | Garbage Collection | 30 Aug 2008, 12:39:00 |
Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.
Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.
This page was created by Crystal 0.999 (Linux 2.4.27/i686).