First Draft: Placement New Expression

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Oct 31 06:33:05 UTC 2024


I recommend that this includes allocator support.

```d
struct Allocator {
     void[] allocate(size_t, TypeInfo ti=null);
     void deallocate(void[]);
}
```

We would need a way to tie into deallocate + destroy. Say perhaps 
``delete(allocator) thing;`` statement?

This little bit of convenience would be a huge QoL improvement, as it'll 
calculate the size needed to be allocated for you (including for say 
arrays). This can be a bit of paid to do properly due to overflow.

 > The size of the memory object of class Type can be retrieved with the 
expression __traits(initSymbol, Type).length.

```d
pragma(msg, __traits(initSymbol, Foo).length);

struct Foo {
	int x;
}
```

```
onlineapp.d(1): Error: cannot determine the address of the initializer 
symbol during CTFE
onlineapp.d(1):        while evaluating `pragma(msg, Foo.length)`
```

We need a CTFE'able solution to this, for that argument to hold.


More information about the dip.development mailing list