Details on how aggregates are constructed with `new` and later destroyed by the GC
Nicholas Wilson
iamthewilsonator at hotmail.com
Mon Oct 8 12:14:47 UTC 2018
On Monday, 8 October 2018 at 11:19:40 UTC, Per Nordlöw wrote:
> I want to understand how calls to `new` for classes
see _d_newclass
> and structs are lowered by the compiler and druntime to a
> GC-allocation (specifically how the `ba`-argument bits are
> determined) followed by an initialization using default
> constructor or via a user-defined constructor called using
> arguments to `new`. And how this is related to the trait
> `hasElaborateConstructor` for both `classes` and `structs`.
Memory is allocated, .init (for classes this comes from
typeid(T).initializer)
is copied over the memory and then the constructor is run.
> I also want to understand how manually defined constructors and
> destructors affect the setting of the GC finalizer for a given
> aggregate type. And how this is related to the trait
> `hasElaborateDestructor` for both `classes` and `structs`
For classes the typeid(T).destructor is called on the class, for
structs I'm not sure.
> Where's the dmd and druntime code that handles these steps?
should be src/rt/lifetime.d IIRC
More information about the Digitalmars-d-learn
mailing list