Andrei:

> bool onStack = smallEnough(length * sizeof(T));
> auto a = (cast(T*) (onStack ? alloca : malloc)(length * sizeof(T)));
> scope(exit) if (!onStack) free(a.ptr);
> initialize(enforce(a));
> scope(exit) clear(a);
> 
> This block is difficult to factor out because of alloca.

As I have explained in my old enhancement request about VLAs and in a recent 
post, this code is dangerous, because alloca() in some implementations 
deallocates at the end of the function, while in other cases it deallocates at 
the end of the scope. A well implemented D-VLA needs be sure to free the stack 
space at the end of the scope.

Bye,
bearophile

Reply via email to