Sunday, November 02, 2008  Somewhat more efficient smart
pointers  There was a little to and fro in the comments on
yesterday's post on more fluent smart pointers.  It wasn't my
intention to create the ultimate in performance for the smart
pointer, so I didn't pay much attention to it; I focused mainly
on getting an effect from composing a number of simple reusable
primitives and ideas.  However, I'd like to point out that since
method references are just interfaces, a more efficient
implementation can simply implement the interface directly. A
yet more efficient implementation might choose to construct a
vtable directly, and use a simple 64-bit value on the heap
(32-bits for the reference count, 32-bits for the instance
pointer), but I'll leave that as an exercise for the reader.
Anyhow, here it is: construction is now sufficient to assign to
a location of type TFunc<T>, rather than needing an extra Wrap
method:  unit ObjHandle2;   uses SysUtils;    TObjectHandle<T:
class> = class(TInterfacedObject, TFunc<T