Placement new and @trusted

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Wed Sep 10 14:45:52 UTC 2025


On 11/09/2025 2:31 AM, IchorDev wrote:
> On Wednesday, 10 September 2025 at 13:13:34 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> The reason placement new is @system is because of double-init. It 
>> can't be a safe operation.
> 
> What?! Like, it assigns to the memory twice? What's the point of this 
> feature, then? I thought this could essentially replace `emplace` for 
> constructing types into uninitialised memory, but instead it's just a 
> booby-trap that stops people from making their code `@safe`?

It does replace emplace, and just like emplace you can double-init 
memory with it. There is no protection against it apart from it being 
@system (which emplace should also be).

The caller is responsible for guaranteeing that the memory passed in is 
uninitialized, and that behavior is @system.


More information about the Digitalmars-d-learn mailing list