Eliminate "new" for class object creation?

Max Samukha spambox at d-coding.com
Tue Oct 20 04:00:06 PDT 2009


On Tue, 20 Oct 2009 18:12:39 +0800, Lionello Lunesu
<lio at lunesu.remove.com> wrote:

>On 20-10-2009 6:38, Andrei Alexandrescu wrote:
>> I hereby suggest we get rid of new for class object creation. What do
>> you guys think?
>
>I don't agree with this one.
>
>There's extra cost involved, and the added keyword makes that clear. 
>Also, somebody mentioned using 'new' to allocate structs on the heap; 
>I've never actually done that, but it sounds like using 'new' would be 
>the perfect way to do just that.
>
>L.

I don't think the extra cost should be emphasized with 'new' every
time you instantiate a class. For example, in C#, they use 'new' for
creating structs on stack (apparently to make them consistent with
classes, in a silly way).

I think the rarer cases when a class instance is allocated in-place (a
struct on heap) can be handled by the library.

BTW, why "in-situ" is better in this context than the more common
"in-place"? Would be nice to know.



More information about the Digitalmars-d mailing list