draft proposal for ref counting in D - BRIEF ROUNDUP

Sönke Ludwig sludwig at outerproduct.org
Sat Oct 12 07:03:11 PDT 2013


I've made short roundup of the different features/requirements that have 
been mentioned (may have forgotten some and added some) as this thread 
has a complexity that presumably makes it quite hard to follow for most 
readers. I have also attached an estimated priority for each requirement 
based on the discussion and my own experiences.

  - Memory safety [very important but also very difficult/limiting]
      Disallow escaping uncounted references to reference counted
      memory. Keywords: pure, scope, isolated/owned
  - COM compatible [important]
      Needs to support internal reference counting using
      AddRef/ReleaseRef, while obeying to the call convention
  - Objective-C compatible [important]
      Weak references, manual memory management and autorelease pools are
      some keywords here
  - Handle reference cycles [nice to have]
      Requires GC memory for storing the instances
  - Weak pointers [critical]
      Only briefly mentioned, but critical for many data structures
      (e.g. graphs or caches) requires external reference counting
  - Not require two separate counts for COM [mildly important]
      Using GC memory would require a second reference count for the
      D side of things, which is not desirable for multiple reasons
  - Support type qualifiers [critical]
      All usual type qualifiers and conversions should work as expected.
      This is not possible in a pure template based solution.
  - Support non-class types [nice to have]
      Although slightly limiting, classes provide a convenient
      abstraction and will arguably capture >90% use cases just fine
  - Support referencing fields/slices [nice to have]
      Letting references to members escape in a safe way would greatly
      increase the flexibility, but ties it tightly to the GC
  - Allow manual memory management [critical]
      For COM/Obj-C and any situation where external code is to take
      responsibility of the ref counting this needs to be an option
  - Not require new annotations [important]
      Getting this to work without introducing new keywords/syntax is
      strongly preferred by Walter
  - Safe shared(RefCountedType) variables [important]
      There needs to be a way to make shared references thread-safe
  - Support OOP reasonably well [important]
      The usual up and down casts should work and calling functions of
      base classes needs to be safe

Please mention any points that I have forgotten so that we have some 
kind of unit test against which proposed designs can be checked.


More information about the Digitalmars-d mailing list