On Sunday, 20 October 2013 at 14:25:37 UTC, bearophile wrote:
I'd like variable-sized stack-allocated arrays in D.

I think I would too, though it'd be pretty important, at least for @safe, to get scope working right.

Ideally, the stack allocated array would be a different type than a normal array, but offer the slice operator, perhaps on alias this, to give back a normal T[] in a scope storage class (the return value could only be used in a context where references cannot escape).

This way, the owner is clear and you won't be accidentally storing it somewhere.



An alternative to a stack allocated array would be one made from a thread-local region allocator, which returns a Unique!T or similar, which frees it when it goes out of scope. Such an allocator would be substantially similar to the system stack, fast to allocate and free, although probably not done in registers and perhaps not as likely to be in cpu cache. But that might not matter much anyway, I don't actually know.

Reply via email to