Memory safe and coroutines are the focus of D.

jmh530 john.michael.hall at gmail.com
Wed Oct 19 18:50:37 UTC 2022


On Monday, 17 October 2022 at 17:50:29 UTC, Araq wrote:
> [snip]
> The distinction between managed and unmanaged pointers can also 
> be found in: C#, C++ (shared_ptr), Rust (Arc), Swift, Go (Go 
> uses 'uint' for untraced pointers IIRC)... In practice it 
> doesn't lead to multiple copies of the same code for two 
> reasons:
> 1. It's clear when to use which pointer type.
> 2. Unmanaged pointers are used much more rarely because 
> automatic memory management simply works much better than 
> manual MM; it's simply much more cost effective.

The ability to create managed and unmanaged pointers is separate 
from built-in language support for them. D has the ability to 
create types like shared_ptr, but it doesn't have the equivalent 
functionality that Nim has in terms of two built-in pointer types.

On 1, even if it is clear to the user what pointer type to use, 
it's not always clear when to use which pointer type from the 
perspective of the library writer. The library writer might want 
the library to be indifferent to what memory management scheme is 
used. They might be in the position of writing two versions of 
the function (or a templated version of the function) that 
supports each of the pointer types.

On 2, I would agree that automatic memory management does tend to 
work better, but that doesn't mean that some people don't want to 
use manual MM.


More information about the Digitalmars-d mailing list