std.allocator needs your help

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Sep 23 08:02:17 PDT 2013


On 9/23/13 7:50 AM, Manu wrote:
> delete is important if your class is being allocated by a pool or
> something...

It's important as an API function, but not as a language primitive. 
"new" should also have been a function.

> But you said before, people won't use 'new' if they are using an
> allocator. I'm really not sure that's a good idea.

I don't see another way if people are to define and use multiple allocators.

> Most people (library authors!) don't actually care about their memory
> allocation, they will continue to use 'new', just because it's a keyword.

"new considered harmful" etc.

> It also screws with generic code; X should be allocated with 'new', but
> Y should be allocated with yAllocator.alloc()?
> What if you decide that Z, which allocates with 'new', becomes a problem
> and you want to switch it into a pool? You now need to track down every
> instance of 'new Z', and change it.

We can only improve that situation by allowing people to replace the 
global allocator with their own allocators. Again, there's a disconnect 
here - I'm discussing "how to make it easy for people to define 
allocators" and you discuss "how to make it possible for people to plug 
allocators, once defined, as the global allocator". These are two 
distinct endeavors. At the level I'm at, I'm concerned with making good 
allocators easy to implement. You may say you don't care, and that's 
good feedback, but it's what I have for the time being.


Andrei



More information about the Digitalmars-d mailing list