Handle surrogates

A handle surrogate is a conduit you use to get to the master object to avoid direct creation or use of the master object. Use handle surrogates to avoid copying large objects that are too big to pass by value, and where internal use of pointers (rather than copying) is preferable. Some handle surrogates are little more than counted pointers wrapped in a class that delegates calls to the master object. Use this technique anywhere that counted pointers are useful--that is, where storage management is difficult due to a multiplicity of references to shared objects.


A handle surrogate is similar to a counted pointer, but because the surrogate has object semantics rather than pointer semantics, it is possible to avoid some of the problems of counted pointers. For example, you can prevent the client from getting hold of a regular C pointer and thus having a dangling reference (which can be avoided with counted pointers, but is a fair bit of work). See "Synchronization techniques" on page 129 for more examples.

Because you don't directly create the master object, the surrogate creates the master when you create the surrogate. Once the master object exists, you can create additional handle objects of the same class that reference that same master. If you are reference counting, the master object exists until the destruction of the last handle, which then destroys the master.

The Taligent Application Environment's kernel interface has such classes as TTaskHandle and TThreadHandle. These have no actual master object (just a reference), and they do not perform reference counting. You must explicitly release the resources they refer to, which can leave dangling references. All such handles need to be safe to use if they contain a dangling reference (for example, throw an exception rather than crash).


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker