<div dir="ltr">On 24 May 2013 19:40, Dmitry Olshansky <span dir="ltr"><<a href="mailto:dmitry.olsh@gmail.com" target="_blank">dmitry.olsh@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">24-May-2013 09:02, Manu пишет:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 24 May 2013 14:11, Marco Leise <<a href="mailto:Marco.Leise@gmx.de" target="_blank">Marco.Leise@gmx.de</a><br></div><div class="im">
<mailto:<a href="mailto:Marco.Leise@gmx.de" target="_blank">Marco.Leise@gmx.de</a>>> wrote:<br>
<br>
    Am Thu, 23 May 2013 20:21:47 -0400<br>
    schrieb "Jonathan M Davis" <<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a><br></div>
    <mailto:<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>>>:<div><div class="h5"><br>
<br>
     > At some point, we're probably going to need to<br>
     > benchmark stuff more agressively and optimize Phobos in general<br>
    more, because<br>
     > it's the standard library. And eliminating unnecessary memory<br>
    allocations<br>
     > definitely goes along with that.<br>
     ><br>
     > - Jonathan M Davis<br>
<br>
    On a related note, a while back I benchmarked the naive Phobos<br>
    approach to create a Windows API (wchar) string from a D<br>
    string with using alloca to convert the string on a piece of<br>
    stack memory like this: <a href="http://dpaste.1azy.net/b60d37d4" target="_blank">http://dpaste.1azy.net/<u></u>b60d37d4</a><br>
    IIRC it was 13(!) times faster for ~100 chars of English text<br>
    and 5 times for some multi-byte characters.<br>
    I think this approach is too hackish for Phobos, but it<br>
    demonstrates that there is much room.<br>
<br>
<br></div></div><div class="im">
I don't think it's hack-ish at all, that's precisely what the stack is<br>
there for. It would be awesome for people to use alloca in places that<br>
it makes sense.<br>
Especially in cases where the function is a leaf or leaf-stem (ie, if<br>
there is no possibility of recursion), then using the stack should be<br>
encouraged.<br>
For safety, obviously phobos should do something like:<br>
   void[] buffer = bytes < reasonable_anticipated_buffer_<u></u>size ?<br>
alloca(bytes) : new void[bytes];<br>
<br></div><div class="im">
toStringz is a very common source of allocations. This alloca approach<br>
would be great in those cases, filenames in particular.<br>
</div></blockquote>
<br>
Alternatively just make a TLS buffer as scratchpad and use that everywhere.</blockquote><div><br></div><div style>How is that any different than just using the stack in practise?</div></div></div></div>