[cfe-dev] objc++ enhancements for new c++ features

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 29 11:21:42 PDT 2018


On 29 Mar 2018, at 19:11, James Gregurich <bayoubengalml at mac.com> wrote:
> 
> ok.    How would I write my own shared/weak smart pointer combo that only uses the objc retain counting without ARC? As I said repeatedly, the only way I can see to do it is have an independent counter...at that point, I'd be re-creating std::shared_ptr and std::weak_ptr anyway. 

I have already answered this once, but to reiterate:

The functions used by ARC are simple C functions.  If you are willing to assume a runtime that supports ARC, then you can simply call objc_retain / objc_release explicitly when compiling with a non-ARC ObjC++ compiler.  I did this years ago to have code that worked with ARC and non-ARC ObjC++.  If you are not willing to assume an ARC-enabled runtime, then you will need a wrapper with a separate reference count to get weak pointers, because the classical retain / release mechanism doesn’t provide the required synchronisation.

David




More information about the cfe-dev mailing list