D’s docs saying that when you use scope for local variables, then they will be allocated on stack (even if you’re allocating class instance). But what about auto keyword? Does it guarantee that the instance will be allocated on stack?
void foo() { auto instance = new MyClass();}void foo() { scope instance = new MyClass();}
So can I suggest that this two statements are equal (in terms of allocation)?
No,
autoonly infers the type.There’s no point in using
autoif you want it to be allocated on the stack; that’s whatscopeis (was) for.They’ve brilliantly (read: not so much) decided to remove
scope,delete, etc. from the language, so it will probably allocate on the heap anyway. Your best bet is to use the function calledscopedin one of the modules, to allocate on the stack.