Hacker News new | past | comments | ask | show | jobs | submit login

Your checklist is only covering the simplest case, direct ownership of small data structures.

I'm not going to put a large array on the stack. I'm not going to pass unique_ptr (exclusive ownership) of every resource I allocate to every caller. I still need to decide between passing a copy, a unique_ptr, a reference, or a shared_ptr. When I design a data structure with interior pointers, I need to define some ownership semantics and make sure they are natural (for example, in a graph that supports cycles, there is no natural notion of ownership between graph nodes).

These are all questions that are irrelevant in a GC langauge, for memory resources.




Not really irrelevant when the said GC language also does value types, e.g.

   // C#
   Span<byte> buffer = stackalloc byte[1024];


True, but even then you only have to decide between passing a copy of the value or a reference to it, no need to think about ownership.


Kind of, if it is a struct with destructors you need to ensure a region exists.

So either do something like

    using MyStructType something = new MyStructType ()
Or a more FP like stuff with

    myVar.WithXYZResource(res => { /* .... */ })
And then consider if it should be a ref struct, so that is only stack allocated.

This from C# point of view, in something like D, there would be another set of considerations.

Still much easier than "in your face ownership management" though, yes.


Well, destructors come up if you have non-memory resources to manage, and there you do go back to ownership and deterministic destruction issues.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: