CXAutoReference

From cxwiki

Revision as of 05:55, 23 February 2018 by Windwalkr (talk | contribs) (Created page with "<div class="mw-parser-output">The CXAutoReference templated class allows reference-counted objects to be passed around while automatically maintaining the correct reference co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The CXAutoReference templated class allows reference-counted objects to be passed around while automatically maintaining the correct reference count. This is a very simple and powerful tool to use for resource management. The referenced object must expose a specific reference counting interface- typically this is achieved by inheriting from DynamicReferenceCount but other techniques are permitted.
 
CXAutoReference<T> is designed to act in a manner syntactically equivalent to T* where possible.

Restrictions

Performance
Reference Cycles
Thread Safety
Conversion to C pointer
Stack-Allocated Objects
 

Techniques

Allocation / Swallow / Reference
Zero-Reference Cache
Passing by const reference
Move operator
Casting
std::swap