A lent resource is conceptually any reference to memory that you do not own and is not garbage collected. D does not have ownership or borrowed concepts in its type system, but there are techniques that we can use to make our job a little easier.
In order to manage lent resources, perform the following steps:
scope
storage class.The scope
storage class is not fully implemented at the time of writing this; however, there are places where it helps. The scope
delegate arguments will not allocate a heap closure and as the compiler improves, it will help to statically catch escaping references.
In the D type system, immutable
is another feature that helps with resource management. A reference to immutable data can be used just like value types—they are cheap to pass around and can be stored with confidence.
Otherwise, unless you rely on the garbage collector, D is essentially in the same boat as C++ with regard to managing lent resources. Code reviews, private copies, and wrapper structs will form the tools you use to keep track of your manually managed resources.
3.142.133.180