<div dir="ltr">On 21 October 2013 11:48, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 10/20/2013 5:59 PM, Jonathan M Davis wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
If that paradigm is frequent enough, it might be worth wrapping it in a<br>
struct. Then, you'd probably get something like<br>
<br>
StaticArray!(int, 10) tmp(n);<br>
int[] a = tmp[];<br>
<br>
which used T[10] if n was 10 or less and allocated T[] otherwise. The<br>
destructor could then deal with freeing the memory.<br>
</blockquote>
<br></div>
Sounds like a good idea - and it should fit in with Andrei's nascent allocator design.<br></blockquote><div><br></div><div>I use this pattern all over the place.</div><div>I don't love it though. It doesn't feel elegant at all and it wastes stack space, but it's acceptable, and I'd really like to see this pattern throughout phobos, especially where strings and paths are concerned.</div>
<div>System interface functions that pass zero-terminated strings through to the OS are the primary offender, needless garbage, those should be on the stack.</div><div><br></div><div>I like to use alloca too where it's appropriate. I'd definitely like if D had a variable-sized static array syntax for pretty-ing alloca.<br>
</div><div><div>I thought about something similar using alloca via a mixin template, but that feels really hackey!</div></div></div></div></div>