Second Draft: Placement New Expression

Paul Backus snarwin at gmail.com
Tue Nov 19 19:08:18 UTC 2024


On Tuesday, 19 November 2024 at 05:17:20 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 19/11/2024 6:05 PM, Richard (Rikki) Andrew Cattermole wrote:
>> Why not support calling the allocator with the size needed?
>> 
>> ```d
>> struct Allocator {
>>      void[] allocate(size_t);
>> }
>> 
>> Allocator a;
>> 
>> new (allocator) S;
>> new (malloc) S;
>> ```
>> 
>> DONE.
>
> There are three reasons that motivate me for allocator support:
>
> 1. It would be @safe.

It would not be @safe, because there is no way the compiler can 
be sure that the void[] returned from allocate will not be 
aliased by other pointers/references/slices. The programmer would 
have to verify that for each individual allocator implementation, 
and use @trusted once they had done so.


More information about the dip.development mailing list