www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Emplacement in D

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
After having read about 


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.
Sep 16 2013
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Monday, 16 September 2013 at 21:35:24 UTC, Nordlöw wrote:
 After having read about 


 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.
Sep 16 2013
parent "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> writes:
Nice!

Thx,
Per
Sep 17 2013