comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Creem <jeff@thecreems.com>
Subject: Re: Large arrays passed to arithmetic operators overflows GNAT stack
Date: Sat, 04 Dec 2010 08:27:30 -0500
Date: 2010-12-04T08:27:30-05:00	[thread overview]
Message-ID: <07sps7-5ju.ln1@newserver.thecreems.com> (raw)
In-Reply-To: <da4fcb09-efa7-46d4-aece-e86b0dcf6674@v17g2000prc.googlegroups.com>

On 12/4/2010 1:32 AM, Jerry wrote:
> For what it's worth, passing large numerical arrays to the arithmetic
> operators in GNAT can cause the stack to overflow (segfault) even when
> the arrays are allocated from the heap. I suppose that indicates that
> they are being copied rather than being passed by reference.
>

In general, GNAT (and most other compilers) don't copy arguments like 
large arrays on the parameters to subprograms. The problem here is 
almost certainly in the return value associated with the subtraction. I 
am not sure I'd say it is impossible but I don't think I have seen any 
Ada implementation that can avoid the creation of the temporary based on 
the internally defined local variable that is generally required to 
construct code the returns an array.

Even if certain cases could be found by the optimizer and made to work, 
there are all sorts of cases where users would end up being surprised 
when temporaries had to be created.

In cases where array slices, assignment and the math involved 'destroy' 
the future values as the current values are being read, the compiler 
would have no choice (given the semantics of the operator) but to 
introduce some temporaries and it would be quite a feat for a compiler 
to figure out how much of a mini-slice temp it would need.

I really think it is a shame that Generic_Real_Arrays was defined the 
way that it was as the pretty code one gets when being able to use infix 
notation is nice but the overhead involved in the resulting copies 
renders the operators useless for all but the smallest of array vectors.



  parent reply	other threads:[~2010-12-04 13:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-04  6:32 Large arrays passed to arithmetic operators overflows GNAT stack Jerry
2010-12-04  9:19 ` Vinzent Hoefler
2010-12-04 13:27 ` Jeffrey Creem [this message]
2010-12-04 14:17 ` Peter C. Chapin
2010-12-05  1:22   ` Jerry
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox