Delay allocating class instance in stack.
ANtlord via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 22 20:08:34 PDT 2017
On Wednesday, 22 March 2017 at 13:19:32 UTC, Nicholas Wilson
wrote:
> On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote:
> You still have the buffer (the class has to go somewhere!), but
> it is implicit (you can't refer to it directly only through the
> class reference) and so is the destructor call, as opposed to
> the emplace + explicit buffer combo. In the latter case the
> class destructor will not be called automatically so you must
> do it yourself with `destroy`.
My bad. It appears I need to clarify. I mean the case that I
create object without delaying. I mean simple construction.
scope myObj = MyClass(1);
Answering own question:
In this case object is allocated using stack (according
documention
https://wiki.dlang.org/Memory_Management#Allocating_Class_Instances_On_The_Stack). Function `destroy` used for cleanup object from heap (according documention https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation).
More information about the Digitalmars-d-learn
mailing list