On the richness of C++

Robert Fraser fraserofthenight at gmail.com
Thu Apr 10 22:38:44 PDT 2008


Kevin Bealer wrote:
> Sean Kelly Wrote:
> 
>> == Quote from Kevin Bealer (kevinbealer at gmail.com)'s article
>>> If you want to do really specific things with memory, C++ lets you do this, but
>>> in D classes can only be handled by their object references.  You can't do a
>>> "placement new" or anything like it with D classes.  In C++ you could build
>>> classes that automatically allocate themself in a shared memory segment, but
>>> in D, probably not.  Note that in practice, this is hard to do right and I think is
>>> rarely used for much.
>> I'd personally like for "placement new" to be supported by the language.  I've
>> considered adding a new(void*) method to Object for this purpose in Tango,
>> but haven't experimented enough to find out if this would cause any problems.
> ...
> 
> I can think of these reasons off hand why (C++) folks do placement new.
> 
> 1. Allocate lots of class objects at once to reduce allocations.
> 
> 2. Allocate-on-stack for objects to avoid allocation altogether.
> 
> 3. Group classes together for memory locality.
> 
> 4. Tricks like surrounding objects with DEADBEEF for memory 
> corruption detection, or adding next or left/right pointers to objects.
> 
> Out of curiosity, what motivates your desire for placement new?
> 
> Kevin

(2) is solved in D by using scope classes. But the others still remain 
vaild reasons why a placement new is useful.



More information about the Digitalmars-d mailing list