new should lower to a template function call

Steven Schveighoffer schveiguy at gmail.com
Fri Jul 24 12:39:09 UTC 2020


On 7/23/20 11:29 PM, Andrei Alexandrescu wrote:
> On 7/23/20 9:34 AM, jmh530 wrote:
>> On Thursday, 23 July 2020 at 00:47:21 UTC, Andrei Alexandrescu wrote:
>>> Was thinking about this, see 
>>> https://issues.dlang.org/show_bug.cgi?id=21065.
>>>
>>> One problem I noticed with the current instrumentation of allocations 
>>> is that it is extremely slow. https://github.com/dlang/dmd/pull/11381 
>>> takes care of that trivially and quickly because it takes advantage 
>>> of defining one static variable per instantiation.
>>
>> How does this fit in with plans for std.experimental.allocator? What 
>> are the current plans for std.experimental.allocator?
> 
> Allocators need a champion. Ideally a good integration with the GC would 
> be achieved but I'm not a GC expert and don't have the time to dedicate 
> to it.
> 
> As far as I know there's little use of allocators, which is unlike C++ 
> where there's a lot of excitement around them in spite of a much scarcer 
> API. I recall there's a little use of allocators (copied to 
> code.dlang.org and improved) in Mir. Not much else I've heard of.
> 
> I was hoping there'd be a lot of experimentation accumulating with new 
> allocators by now, for example to this day I have no idea whether 
> FreeTree is any good. (It never rebalances, but I thought I'd wait until 
> someone says the trees get lopsided... still waiting).

iopipe uses allocators, though I had to write my own default GC 
allocator, because I needed an allocator that doesn't provide blocks 
with SCAN set.

At least in one place I used it to avoid using the heap (for a basic 
output pipe): 
https://github.com/schveiguy/iopipe/blob/0974b19e389e0c35779fa2d5b4690f775264239d/source/iopipe/bufpipe.d#L618-L633

And in action here: 
https://github.com/schveiguy/httpiopipe/blob/a04d87de3aa3836c07d181263c399416ba005e7c/source/iopipe/http.d#L761

I think something that might help gain more traction is to provide a 
mechanism to ask for typed data. Some allocators need to do things when 
they have types. For example, the GC can run destructors on structs when 
allocated properly.

If allocators are not going to provide complete replacement for GC 
calls, then one is going to have to use conditional compilation to make 
it work.

-Steve


More information about the Digitalmars-d mailing list