Placement New, Was: (Re: auto, var, raii,scope, banana)

Chris Miller chris at dprogramming.com
Thu Jul 27 10:35:53 PDT 2006


On Wed, 26 Jul 2006 01:23:53 -0400, Regan Heath <regan at netwin.co.nz> wrote:

> On Wed, 26 Jul 2006 00:23:41 -0400, Chris Miller  
> <chris at dprogramming.com> wrote:
>> On Wed, 26 Jul 2006 00:13:53 -0400, Regan Heath <regan at netwin.co.nz>  
>> wrote:
>>> 1. 'new' implies heap allocation
>>
>> Except when it doesn't.  I'm talking about overloaded 'new'
>>
>> If Object`s were given 2 default new() implmentations, one that does  
>> the current allocation, and another that allows you to specify a buffer  
>> (also so that every Joe who wants this doesn't have to derive from the  
>> class to provide it). When RAII is involved, it can choose which  
>> version of new() to use (implementaion defined), using stack or not.
>
> You're describing 'placement' new, yes?
> http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=160&rl=1
>
> I dont think D has placement new, at least not a syntax for it like C++.  
> I could be wrong.
>
> You're right in that if D were to get placement new using the C++ syntax  
> then the suggested RAII syntax (removing 'new') would make it impossible  
> to declare an RAII class using placement new. But, it appears that  
> placement new in D is done with a custom allocator and not a special  
> syntax?
>
> http://www.digitalmars.com/d/memory.html#newdelete

I hadn't thought of 'placement' new but this page is what I was referring  
to. Scroll down to "Allocating Class Instances On The Stack" to see what I  
meant. Different uses of 'new' (RAII/regular) could call different new()s,  
which doesn't imply heap.



More information about the Digitalmars-d mailing list