Am 04.11.2012 18:41, schrieb Andrei Alexandrescu:
On 11/4/12 12:35 PM, Tommi wrote:
I have a fundamental language design talking point for you. It's not
specific to D. I claim that, most of the time, a programmer cannot, and
shouldn't have to, make the decision of whether to allocate on stack or
heap.

I don't think that claim is valid. As a simple example, polymorphism
requires indirection (due to variations in size of the dynamic type
compared to the static type) and indirection is strongly correlated with
dynamic allocation. Also, the value vs. reference semantics of type are
strongly correlated with where objects should go. So on the contrary,
quite often heap vs. stack allocation is forced by the nature of what's
allocated.

Andrei


Java and Go work around this issue using escape analysis, in opposite directions though.

In Java most JITs can allocate objects in the stack if they see the object does not escape the local scope.

Go goes the other way, by allocating in the heap local objects that are usually allocated on the stack but are returned the caller.

--
Paulo

Reply via email to