Le 26/12/2011 18:25, Andrei Alexandrescu a écrit :
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

The first thing that I see looking at the source code is how many null check you'll find in RefCounted . As the RefCounted struct is useless without a payload, we should ensure that the payload exists, in all cases, and not null check at every operation.

Reply via email to