Small Memory Allocation, Part 3

There are a couple of differences from a regular COM smart pointer (CComPtr, for example [6]):

BREW interfaces can be created by using a constructor taking UID as the only parameters. Alternative implementations, more in the spirit of CComPtr using dedicated methods or factories, are equally possible (and marginally better if considering the additional failure support).

BrewIPtr takes immediate ownership of raw interface pointers when used with BREW_Policy. This encourages the use of smart pointers and avoids all direct reference counting manipulation. COM_Policy allows the same behavior as a smart COM pointer (that's why the attach/detach pair).

BREW interfaces are used in the C style, making pointer operators overloading superfluous.

Taking into account the C implementation of BREW, there is no way to prohibit the use of AddRef or Release on a BrewIPtr. BREW_Policy makes interfaces access more uniform and doesn't encourage this kind of mistakes.

The use of BrewIPtr is illustrated in two contrasting examples, one using BREW_Policy and the other COM_Policy.