<div dir="ltr">On 24 September 2013 01:02, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 9/23/13 7:50 AM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
delete is important if your class is being allocated by a pool or<br>
something...<br>
</blockquote>
<br></div>
It's important as an API function, but not as a language primitive. "new" should also have been a function.</blockquote><div><br></div><div>I like operator new. It goes blue, and the statement isn't riddled with exclamation marks.</div>
<div>Imagine if new was a template (it would have to be a template). Allocating a template would require nested template syntax every time, which is pretty ugly.</div><div><br></div><div>  X x = new!(X!arg(args...)); // ewoo, paren spam...</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But you said before, people won't use 'new' if they are using an<br>
allocator. I'm really not sure that's a good idea.<br>
</blockquote>
<br></div>
I don't see another way if people are to define and use multiple allocators.</blockquote><div><br></div><div>Well if an allocator is somehow associated with a class/struct, then 'new MyClass' would invoke that allocator.</div>
<div>If you:</div><div>  pushThreadAllocator(myAllocator);</div><div>  X x = new X;</div><div>  popThreadAllocator();</div><div><br></div><div>Then new will use your thread-local allocator.</div><div>Continue for global, fiber, etc.</div>
<div><br></div><div>Maybe there's opportunity for 'scope' to offer some nice convenience here?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Most people (library authors!) don't actually care about their memory<br>
allocation, they will continue to use 'new', just because it's a keyword.<br>
</blockquote>
<br></div>
"new considered harmful" etc.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It also screws with generic code; X should be allocated with 'new', but<br>
Y should be allocated with yAllocator.alloc()?<br>
What if you decide that Z, which allocates with 'new', becomes a problem<br>
and you want to switch it into a pool? You now need to track down every<br>
instance of 'new Z', and change it.<br>
</blockquote>
<br></div>
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.</blockquote>
<div><br></div><div>Well, I'm discussing "how do people affect/override 'new' in various circumstances?"</div><div><br></div><div>But sure, I said before, if we're limiting this discussion to the API of an allocator then it looks fine, I see no obvious issues.</div>
<div>But I think the question requires consideration of the intended goal to make informed decisions about the design, even at this level.</div></div></div></div>