Core Foundation框架(2)命名规范,内省

命名规则中最重要的就是Create Rule,官方说明如下:

There is an important distinction between Get, and Copy and Create, in names of functions that return values. If you use a Get function, you cannot be certain of the returned object’s life span. To ensure the persistence of such an object you can retain it (using the CFRetain function) or, in some cases, copy it. If you use a Copy or Create function, you are responsible for releasing the object (using the CFRelease function). For more details, see Memory Management Programming Guide for Core Foundation.

即如果是通过Get方式返回的对象(而不是指针,对应的Cocoa中Get函数返回的时指针),你不需要负责release这个对象,但是不保证对象的生命周期。如果是Create 或者是Copy方式生成的对象,则保证生命周期,但是需要负责Release.

有的函数名字叫做createCopy,这就说明第一个参数需要传入一个分配器。

 

有的函数需要支持多态,比如CFCopyDescription,CFShow等等,这是需要传入参数是CFType类型才能保证可以多态。

一般函数定义如下:

CFStringRef CFCopyDescription(CFTypeRef cf);

void CFShow(CFTypeRef obj);

而CFTypeRef仅仅定义为:typedef const void * CFTypeRef;

转载于:https://www.cnblogs.com/CharlieSu/p/4609810.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值