5 days ago Re: First Draft: Placement New Expression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 1 November 2024 at 19:56:04 UTC, Walter Bright wrote:
> On 10/30/2024 11:33 PM, Richard (Rikki) Andrew Cattermole wrote:
>> We need a CTFE'able solution to this, for that argument to hold.
>
> Currently, there isn't a compile time solution for the allocated size of a class object.
__traits(classInstanceSize, T) works at compile time.
|
5 days ago Re: First Draft: Placement New Expression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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. |
4 days ago Re: First Draft: Placement New Expression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On 11/1/2024 1:02 PM, Paul Backus wrote:
> __traits(classInstanceSize, T) works at compile time.
Ehhxcellent!!
|
4 days ago Re: First Draft: Placement New Expression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | After thinking about this a bit, this expression is going to have to be ``@system``. Unfortunately this compiles: ```d cast(void[])new int[1]; ``` And so would this, without calling the destructor: ```d T* t = new T(...); new(t)T(...) ``` |
4 days ago Re: First Draft: Placement New Expression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On 02/11/2024 6:47 PM, Richard (Rikki) Andrew Cattermole wrote:
> After thinking about this a bit, this expression is going to have to be ``@system``.
>
> Unfortunately this compiles:
>
> ```d
> cast(void[])new int[1];
> ```
>
> And so would this, without calling the destructor:
>
> ```d
> T* t = new T(...);
> new(t)T(...)
> ```
Given this, I have to ask the question, what is the purpose of adding this expression to the language if it cannot be ``@safe``?
For ``@system`` tasks like initialization it should be expected to have to import and call functions to do that action, as it should not occur in normal code.
Would it not be better to do a bit of design work on ``emplace`` instead to improve its usability so that it consistently has this form:
```d
size_t calculateSizeOf(T)();
size_t calculateSizeOf(T)(size_t count);
T emplace(T)(void[]);
```
|
4 days ago Re: First Draft: Placement New Expression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Am 31.10.2024 um 07:23 schrieb Walter Bright: > Based on a suggestion by Manu Evans: > > https://github.com/WalterBright/documents/ blob/5d65426a4e5c434d571e76ae800a267a610bf394/placementnew.md Should probably mention the old "class allocators": https://dlang.org/deprecate.html#Class%20allocators%20and%20deallocators |
Copyright © 1999-2021 by the D Language Foundation