D on next-gen consoles and for game development

Manu turkeyman at gmail.com
Thu May 23 22:02:21 PDT 2013


On 24 May 2013 14:11, Marco Leise <Marco.Leise at gmx.de> wrote:

> Am Thu, 23 May 2013 20:21:47 -0400
> schrieb "Jonathan M Davis" <jmdavisProg at gmx.com>:
>
> > At some point, we're probably going to need to
> > benchmark stuff more agressively and optimize Phobos in general more,
> because
> > it's the standard library. And eliminating unnecessary memory allocations
> > definitely goes along with that.
> >
> > - Jonathan M Davis
>
> On a related note, a while back I benchmarked the naive Phobos
> approach to create a Windows API (wchar) string from a D
> string with using alloca to convert the string on a piece of
> stack memory like this: http://dpaste.1azy.net/b60d37d4
> IIRC it was 13(!) times faster for ~100 chars of English text
> and 5 times for some multi-byte characters.
> I think this approach is too hackish for Phobos, but it
> demonstrates that there is much room.
>

I don't think it's hack-ish at all, that's precisely what the stack is
there for. It would be awesome for people to use alloca in places that it
makes sense.
Especially in cases where the function is a leaf or leaf-stem (ie, if there
is no possibility of recursion), then using the stack should be encouraged.
For safety, obviously phobos should do something like:
  void[] buffer = bytes < reasonable_anticipated_buffer_size ?
alloca(bytes) : new void[bytes];

toStringz is a very common source of allocations. This alloca approach
would be great in those cases, filenames in particular.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130524/582f015b/attachment.html>


More information about the Digitalmars-d mailing list