D on next-gen consoles and for game development

Jonathan M Davis jmdavisProg at gmx.com
Thu May 23 17:21:47 PDT 2013


On Friday, May 24, 2013 10:11:17 Manu wrote:
> /agree, except the issue I raised, when ~ is used in phobos.
> That means that function is now off-limits. And there's no way to know
> which functions they are...

Yes, we need to look at that. I actually don't think that ~ gets used much 
(primarily because so much of it uses ranges which don't have ~), but it's 
something that we need to look out for and address. The suggestion of an @nogc 
attribute which at least guarantees that new isn't used would be nice for 
that, since it could potentially both guarantee it and document it. But that 
woludn't work with templated functions for the most part, since types being 
used with them might allocate, though we could presumably add attribute 
inferrence for that so that the functions which call them can be marked with 
@nogc and be able to know that the functions that they're calling obey that.

My guess is that the functions which are most likely to allocate are those 
which specifically take strings or arrays, as they _can_ use ~, so they 
probably need to be examined first, but in some cases, they're also the type of 
function which may _have_ to allocate, depending on what they're doing. 
Probably the right approach for that is to track down all of those that are 
allocting, make it so that any of those that can avoid the allocation do, and 
then create overloads which take an output range or somesuch for those that 
have to allocate so that preallocated memory and the like can be used for 
them. And if we actually have any which can't possibly do anything but 
allocate, they should be clearly documented as such.

All around though, figuring out how to minimize GC usage in Phobos and enforce 
that is an open problem which is still very much up for discussion on how best 
to address (particularly when it's quite easy to introduce inadventant 
allocations with some stuff). But with everything else that we've had to worry 
about, optimizations like that haven't been as high a priority as they're 
going to need to be long term. 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


More information about the Digitalmars-d mailing list