First Draft: Placement New Expression

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sat Nov 2 03:14:24 UTC 2024


On 02/11/2024 8:53 AM, Walter Bright wrote:
> On 10/30/2024 11:33 PM, Richard (Rikki) Andrew Cattermole wrote:
>> I recommend that this includes allocator support.
> 
> An allocator should be able to deliver a void[], I'm not seeing where 
> specialized support for it is needed.

The specialized support is that the compiler will call ``allocate`` with 
the appropriate size for you.

```d
T* t = new(allocator)T;
```

Is a whole lot better than:

```d
T* t = new(allocator.allocate(T.sizeof))T;
```

Especially with dynamic arrays, classes, structs all having different 
size calculations that you need to do.

Otherwise, I see no benefit when using allocators to use this syntax. 
Might as wrap it with the free-function ``make`` and ``makeArray`` that 
calls ``emplace``.

This will definitely come up again after implementation, it's too good 
of a QoL addition to not add.



More information about the dip.development mailing list