Emplacement in D

monarch_dodra monarchdodra at gmail.com
Mon Sep 16 23:15:09 PDT 2013


On Monday, 16 September 2013 at 21:35:24 UTC, Nordlöw wrote:
> After having read about 
> http://dlang.org/phobos/std_conv.html#.emplace
>
> I wonder: Considering the fact that D has stricter control over 
> memory, couldn't the need for emplace be removed through clever 
> D compiler optimization when for example adding structs at the 
> end of an array and assuming its constructor is safe?
>
> At least If all the members recursively have value semantics it 
> would be obvious right? But maybe that is a corner case.

Emplace is designed for user control, when the user wants to 
"emplace" an object over already allocated memory. It's basically 
just for user managed memory.

Appending to an array *is* managed by the compiler (well, 
druntime to be exact), via postblit. EG: memcpy followed by 
postblit.

That said, druntime does this completly... "runtime", so isn't as 
optimal as it could be, but it's something we are working on.


More information about the Digitalmars-d mailing list