zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    C# 反射修改私有静态成员变量
    symfony2 controller
    symfony2 路由工作原理及配置
    symfony2 安装并创建第一个页面
    git操作命令
    Node异步I/O、事件驱动与高性能服务器
    nodejs get/request
    nodejs events模块
    nodejs 小爬虫
    nodejs API
  • 原文地址:https://www.cnblogs.com/CharlieSu/p/4609810.html
Copyright © 2011-2022 走看看