Generic and fundamental language design issue

deadalnix deadalnix at gmail.com
Sun Nov 4 16:09:39 PST 2012


Le 04/11/2012 18:41, Andrei Alexandrescu a écrit :
> 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.
>

If it is proven that the object is scoped, then allocating it on stack 
make sens as well, even if it will be used only by reference.


More information about the Digitalmars-d mailing list