October 19, 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.
October 19, 2022
On Wednesday, 19 October 2022 at 18:50:37 UTC, jmh530 wrote:
>
> 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.

It usually very clear what pointer type to use and you can see it everywhere in other languages. It is that they use the native managed pointer for libraries intended to be used in the language. Like in C#, you never see raw pointers in libraries only the native reference and value types.

If you create FFI functions intended to be used by many languages, then you have no choice other than using raw pointers which is only common denominator there is.

1 2
Next ›   Last »