Iray Programmer's Manual

Handle class

To simplify keeping track of reference counting and necessary release() calls on interfaces, Iray offers a handle class, mi::base::Handle. This handle class maintains a pointer semantic while supporting reference counting for interface pointers. For example, the -> operator acts on the underlying interface pointer. The destructor calls release() on the interface pointer, copy constructor and assignment operator take care of retaining and releasing the interface pointer as necessary. Note that it is also possible to use other handle class implementations, for example, std::tr1::shared_ptr (or boost::shared_ptr).

Note:
  • The handle class has two different constructors to deal with ownership of the interface pointer. See the mi::base::Handle documentation for details.
  • It is also possible to use other handle class implementations, for example, std::tr1::shared_ptr (or boost::shared_ptr). In case you prefer to use such handle classes, you have to ensure that their destructor calls the release() method of the interface pointer. This can be achieved by passing an appropriate argument as second parameter, for example:
    001 std::tr1::shared_ptr p (mi_neuray_factory(), std::mem_fun (&T::release));