D newb
JAnderson
ask at me.com
Sun Aug 17 19:04:15 PDT 2008
Steven Schveighoffer wrote:
> "bearophile" wrote
>> Robert Fraser:
>>> scope Foo f = new Foo();
>>>
>>> The "scope" keyword in the declaration says to the compiler "this will
>>> not escape the function" thus creating the data on the stack. "f" is
>>> still a reference type in this case, however (although it may not be
>>> implemented as a reference -- that's up o the compiler).
>> But the 'scope' works only in some situations, the original poster can
>> take a look at the docs about 'scope'.
>>
>> My question: does the compiler raise a compilation error if the 'scope'
>> keyword is used where the compiler can't actually allocate the class on
>> the stack? (if not, then I think it may be better for the compiler to
>> raise such error, avoiding the illusion of efficiency).
>
> In what situations does it not work?
>
> As long as the class is not too large for the stack (which is very
> unlikely), it should be able to allocate.
>
> -Steve
>
>
If the class has a component sub-class the component may be heap
allocated. I don't agree with making that an error though.
-Joel
More information about the Digitalmars-d
mailing list