Classes and Structs, Memory management questions

ikod via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 2 22:33:57 PDT 2016


On Friday, 2 September 2016 at 08:43:45 UTC, dom wrote:


> Since garbage collection is a very nice feature that I wouldn't 
> wanna miss for certain scenarios I think D should give us the 
> opportunity to determine how an object is allocated. In the 
> example above putting it on the stack is probably a good idea. 
> Having a self managed reference to the heap can be good too if 
> manual memory management is wanted. Or of course let the GC 
> manage it ( i love it for prototyping code and also as a D 
> beginner it is beneficial that i just dont need to care about 
> memory management).
>
> Could somebody explain to me if this is seen as a problem 
> why/whynot and how I should address that kind of issues in my 
> code?

You can allocate class instance on stack:

https://dlang.org/phobos/std_typecons.html#.scoped



More information about the Digitalmars-d-learn mailing list