stack vs. heap alloc syntax

Sean Kelly sean at f4.ca
Sat Feb 18 20:20:39 PST 2006


Mike Capp wrote:
> In article <dt7tv8$2npe$1 at digitaldaemon.com>, Kramer says...
>> I don't want to pull this thread off it's original intentions, but just talking
>> about improving performance and showing off D's features, I was curious if
>> there's been any news on the change Walter was making (I think?) so that an
>> object could be allocated on the stack or heap by means of the syntax:
>>
>> Obj o = Obj(); // stack
>> or
>> Obj 0 = new Obj(); // class
> 
> Alternatively... it's often been observed that auto objects could and probably
> should be allocated on the stack, so why not implement and use that, rather than
> adding new syntax? If the class in question has no destructor there shouldn't be
> any cleanup overhead.
> 
> (Disclaimer: I believe 'auto' has gained extra meanings since last time I looked
> at D in any detail; I'm talking about the old limited-RAII attribute.)

'auto' has gained a new meaning, and using it for both is somewhat 
confusing.  Also, in some cases I want a guarantee that heap allocation 
will not occur rather than to rely on the knowledge that stack 
allocating is simply a common optimization.


Sean



More information about the Digitalmars-d mailing list