On Monday, 26 December 2011 at 17:25:12 UTC, Andrei Alexandrescu wrote:
Hello,

I've been playing with a new approach to reference counting, in particular for the containers library.

A small prototype is at http://pastebin.com/WnSQY1Jw. The prototype features a simple doubly-linked list implementation DListImpl. That is not supposed to be manipulated directly (or it might, in case the user wants a simple garbage collected implementation - this is a point in the discussion).

DListImpl has only a couple of primitives implemented. The only interesting points that it tries to make are:

(a) the presence of the dispose() primitive, which deallocates all memory and brings the object back to its .init state

(b) the presence of the dup() primitive, which creates a full-blown duplicate of the object.

The interesting part of the sample is RefImpl, which has a couple of quite interesting details:

(a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to the held object escapes.

(b) A const/immutable call against a non-existing is silently converted into a call against a default-initialized object.

(c) If a call works and returns the same type for a non-const and a const object, then the const version is preferred. This is to reduce the number of calls to ensureUnique().

Destroy.

Andrei

Maybe the fact that the container is duplicated on opDispatch call time and not on assignment time could be confusing to at least developers coming from c++. It does benefit from lazy duplication by doing it this way which might justify it.

Otherwise it seems good.

/Jonas


Reply via email to