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,7bdbcdc23dd9313d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 04 Dec 2010 08:17:35 -0600 Date: Sat, 04 Dec 2010 09:17:08 -0500 From: "Peter C. Chapin" Organization: Vermont Technical College User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Large arrays passed to arithmetic operators overflows GNAT stack References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-CEAA6h2ndj8Q7mc+3BkkbKKK0AMBeQFyRfyu4a5DphHJOKADXLaUjcS6X9fEWOR6goScahUK8Vo02Xx!qOXzLHXFZlL7WdbmWEqG+YR3VuWFoFtzUVMT7Zu8jL4H6LM5X9mHiKfBkWwL7nA= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2644 Xref: g2news2.google.com comp.lang.ada:16770 Date: 2010-12-04T09:17:08-05:00 List-Id: On 2010-12-04 01:32, Jerry wrote: > with > Ada.Numerics.Long_Real_Arrays; > use > Ada.Numerics.Long_Real_Arrays; > procedure array_test is > type Real_Vector_Access is access Real_Vector; > N : Integer := 1_048_130; > t_Ptr : Real_Vector_Access := new Real_Vector(0 .. N); > t : Real_Vector renames t_Ptr.all; I don't think you need this renaming. If you do t_Ptr'Range or t_Ptr(i) the compiler will forward those operations directly to the object. > t_Diff_Ptr : Real_Vector_Access := new Real_Vector(0 .. N - 1); > t_Diff : Real_Vector renames t_Diff_Ptr.all; > begin > for i in t'range loop > t(i) := 1.0; > end loop; > t_Diff := t(1 .. N) - t(0 .. N - 1); I believe a temporary object (on the stack) needs to be created here to hold the result of the difference before it gets assigned to t_Diff. So despite the fact that the result is ultimately stored on the heap it ends up passing through the stack on its way. If I'm correct it's not the subtraction operator itself that is causing the problem but rather what is happening with the result. In short "-" is returning the array by value and not an access to the array. The compiler has to figure out what to do with that value before assigning it to t_Diff and it is using a stack temporary. Peter