Classes on stack
Redwan
rdwnsjjd at gmail.com
Thu Sep 1 17:59:18 UTC 2022
On Thursday, 1 September 2022 at 13:53:06 UTC, IGotD- wrote:
> On Thursday, 1 September 2022 at 09:43:55 UTC, Redwan wrote:
>> On Thursday, 1 September 2022 at 09:40:06 UTC, Dennis wrote:
>>> On Thursday, 1 September 2022 at 09:13:56 UTC, Redwan wrote:
>>>> [...]
>>>
>>> You can use that using the `scope` storage class on a local
>>> variable with a class type:
>>>
>>> https://dlang.org/spec/attribute.html#scope-class-var
>>>
>>> ```D
>>> void main() @nogc
>>> {
>>> scope o = new Object();
>>> }
>>> ```
>>>
>>> The `@nogc` attribute ensures no allocations are made with
>>> the Garbage Collector.
>>
>> oh, thank you. with this, no allocation??
>
>
> If you have any classes in the class you allocate on the stack,
> the constructor of the class will allocate them on the heap.
> Basically only the top level class will be on stack.
Can you give an example?
More information about the Digitalmars-d
mailing list