On Saturday, 4 March 2017 at 18:09:10 UTC, Anthony wrote:
[snip]

It can be done. C standard library, and thus malloc(), calloc() and free() come with the standard library. There also are more high-level was to do it, std.typecons.scoped, std.experimental.allocator and Dlib (a dub package) to name a few. You do not have to resign any parts of D standard library to do that.

That being said, manual memory management is recommended only if you have a specific reason to use it, because D compiler cannot verify memory safety of code doing such things. But remember that neither could C++. In D you can still at least have the compiler to verify those parts of the code where you don't manage memory manually. So definitely you're better off than in c++ in this regard.

Value types initialized directly on the stack are deterministicly destroyed without having to compromise @safe. (@safe means code which compiler verifies for memory safety. It isn't perfect, but close enough to catch almost all errors) Of course, not everything can be a value type because some data needs to have a variable size.

Scoped pointers is an upcoming feature which should, as I understand it, allow deterministic memory management with reference types too, in @sfe code. It is already implemented, but still seems to me to have too much unfinished corner cases to do its job yet. The standard library is not yet compilant with that feature. I believe, trough, that it will become much better.

That all assuming that "deterministic" means deterministic freeing of the memory and calling of destructors.

Reply via email to