AutomaticReferenceCounting.html#runtime-support
https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support
Runtime support
This section describes the interaction between the ARC runtime and the code generated by the ARC compiler. This is not part of the ARC language specification; instead, it is effectively a language-specific ABI supplement, akin to the “Itanium” generic ABI for C++.
Ownership qualification does not alter the storage requirements for objects, except that it is undefined behavior if a __weak
object is inadequately aligned for an object of type id
. The other qualifiers may be used on explicitly under-aligned memory.
The runtime tracks __weak
objects which holds non-null values. It is undefined behavior to direct modify a __weak
object which is being tracked by the runtime except through an objc_storeWeak, objc_destroyWeak, or objc_moveWeak call.
The runtime must provide a number of new entrypoints which the compiler may emit, which are described in the remainder of this section.
Rationale
Several of these functions are semantically equivalent to a message send; we emit calls to C functions instead because:
- the machine code to do so is significantly smaller,
- it is much easier to recognize the C functions in the ARC optimizer, and
- a sufficient sophisticated runtime may be able to avoid the message send in common cases.
Several other of these functions are “fused” operations which can be described entirely in terms of other operations. We use the fused operations primarily as a code-size optimization, although in some cases there is also a real potential for avoiding redundant operations in the runtime.
id objc_autorelease(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it adds the object to the innermost autorelease pool exactly as if the object had been sent the autorelease
message.
Always returns value
.
void objc_autoreleasePoolPop(void *pool);
Precondition: pool
is the result of a previous call to objc_autoreleasePoolPush on the current thread, where neither pool
nor any enclosing pool have previously been popped.
Releases all the objects added to the given autorelease pool and any autorelease pools it encloses, then sets the current autorelease pool to the pool directly enclosing pool
.
void *objc_autoreleasePoolPush(void);
Creates a new autorelease pool that is enclosed by the current pool, makes that the current pool, and returns an opaque “handle” to it.
Rationale
While the interface is described as an explicit hierarchy of pools, the rules allow the implementation to just keep a stack of objects, using the stack depth as the opaque pool handle.
id objc_autoreleaseReturnValue(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it makes a best effort to hand off ownership of a retain count on the object to a call toobjc_retainAutoreleasedReturnValue for the same object in an enclosing call frame. If this is not possible, the object is autoreleased as above.
Always returns value
.
void objc_copyWeak(id *dest, id *src);
Precondition: src
is a valid pointer which either contains a null pointer or has been registered as a __weak
object. dest
is a valid pointer which has not been registered as a __weak
object.
dest
is initialized to be equivalent to src
, potentially registering it with the runtime. Equivalent to the following code:
void objc_copyWeak(id *dest, id *src) {
objc_release(objc_initWeak(dest, objc_loadWeakRetained(src)));
}
Must be atomic with respect to calls to objc_storeWeak
on src
.
void objc_destroyWeak(id *object);
Precondition: object
is a valid pointer which either contains a null pointer or has been registered as a __weak
object.
object
is unregistered as a weak object, if it ever was. The current value of object
is left unspecified; otherwise, equivalent to the following code:
void objc_destroyWeak(id *object) {
objc_storeWeak(object, nil);
}
Does not need to be atomic with respect to calls to objc_storeWeak
on object
.
id objc_initWeak(id *object, id value);
Precondition: object
is a valid pointer which has not been registered as a __weak
object. value
is null or a pointer to a valid object.
If value
is a null pointer or the object to which it points has begun deallocation, object
is zero-initialized. Otherwise, object
is registered as a __weak
object pointing to value
. Equivalent to the following code:
id objc_initWeak(id *object, id value) {
*object = nil;
return objc_storeWeak(object, value);
}
Returns the value of object
after the call.
Does not need to be atomic with respect to calls to objc_storeWeak
on object
.
id objc_loadWeak(id *object);
Precondition: object
is a valid pointer which either contains a null pointer or has been registered as a __weak
object.
If object
is registered as a __weak
object, and the last value stored into object
has not yet been deallocated or begun deallocation, retains and autoreleases that value and returns it. Otherwise returns null. Equivalent to the following code:
id objc_loadWeak(id *object) {
return objc_autorelease(objc_loadWeakRetained(object));
}
Must be atomic with respect to calls to objc_storeWeak
on object
.
Rationale
Loading weak references would be inherently prone to race conditions without the retain.
id objc_loadWeakRetained(id *object);
Precondition: object
is a valid pointer which either contains a null pointer or has been registered as a __weak
object.
If object
is registered as a __weak
object, and the last value stored into object
has not yet been deallocated or begun deallocation, retains that value and returns it. Otherwise returns null.
Must be atomic with respect to calls to objc_storeWeak
on object
.
void objc_moveWeak(id *dest, id *src);
Precondition: src
is a valid pointer which either contains a null pointer or has been registered as a __weak
object. dest
is a valid pointer which has not been registered as a __weak
object.
dest
is initialized to be equivalent to src
, potentially registering it with the runtime. src
may then be left in its original state, in which case this call is equivalent toobjc_copyWeak, or it may be left as null.
Must be atomic with respect to calls to objc_storeWeak
on src
.
void objc_release(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it performs a release operation exactly as if the object had been sent the release
message.
id objc_retain(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it performs a retain operation exactly as if the object had been sent the retain
message.
Always returns value
.
id objc_retainAutorelease(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it performs a retain operation followed by an autorelease operation. Equivalent to the following code:
id objc_retainAutorelease(id value) {
return objc_autorelease(objc_retain(value));
}
Always returns value
.
id objc_retainAutoreleaseReturnValue(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it performs a retain operation followed by the operation described in objc_autoreleaseReturnValue. Equivalent to the following code:
id objc_retainAutoreleaseReturnValue(id value) {
return objc_autoreleaseReturnValue(objc_retain(value));
}
Always returns value
.
id objc_retainAutoreleasedReturnValue(id value);
Precondition: value
is null or a pointer to a valid object.
If value
is null, this call has no effect. Otherwise, it attempts to accept a hand off of a retain count from a call to objc_autoreleaseReturnValue on value
in a recently-called function or something it calls. If that fails, it performs a retain operation exactly like objc_retain.
Always returns value
.
id objc_retainBlock(id value);
Precondition: value
is null or a pointer to a valid block object.
If value
is null, this call has no effect. Otherwise, if the block pointed to by value
is still on the stack, it is copied to the heap and the address of the copy is returned. Otherwise a retain operation is performed on the block exactly as if it had been sent the retain
message.
id objc_storeStrong(id *object, id value);
Precondition: object
is a valid pointer to a __strong
object which is adequately aligned for a pointer. value
is null or a pointer to a valid object.
Performs the complete sequence for assigning to a __strong
object of non-block type [*]. Equivalent to the following code:
id objc_storeStrong(id *object, id value) {
value = [value retain];
id oldValue = *object;
*object = value;
[oldValue release];
return value;
}
Always returns value
.
[*] | This does not imply that a __strong object of block type is an invalid argument to this function. Rather it implies that an objc_retain and not anobjc_retainBlock operation will be emitted if the argument is a block. |
id objc_storeWeak(id *object, id value);
Precondition: object
is a valid pointer which either contains a null pointer or has been registered as a __weak
object. value
is null or a pointer to a valid object.
If value
is a null pointer or the object to which it points has begun deallocation, object
is assigned null and unregistered as a __weak
object. Otherwise, object
is registered as a __weak
object or has its registration updated to point to value
.
Returns the value of object
after the call.
AutomaticReferenceCounting.html#runtime-support的更多相关文章
- Zend Guard Run-time support missing问题的解决
Zend Guard不仅可以实现对PHP应用的脚本进行加密保护和对PHP应用的产品进行商业许可证管理,还可以为许多软件生产商.IT服务提供商提供完善的加密和安全的产品发布系统. 虽然现在可以成功加密p ...
- PHP:使用Zend对源码加密、Zend Guard安装以及Zend Guard Run-time support missing的解决方法
Zend Guard是目前市面上最成熟的PHP源码加密产品了.刚好需要对自己的产品进行加密,折腾了一晚上,终于搞定,将碰到的问题及解决方法记录下来,方便日后需要,也可以帮助其他人.我使用的是Wamps ...
- Zend Guard Run-time support missing 问题的解决
Zend Guard是目前市面上最成熟的PHP源码加密产品了. 刚好需要对自己的产品进行加密,折腾了一晚上,终于搞定,将碰到的问题及解决方法记录下来,方便日后需要,也可以帮助其他人. 我使用的是Wam ...
- 编译OpenCV文档
概述 使用OpenCV的过程中经常查看文档,每次都去官网查看,不过国内访问速度很慢,有一份本地的文档就好了.本文列出了在Linux(Fedora)系统上从OpenCV源码编译出documentatio ...
- Android Studio NDK编程-环境搭建及Hello!
一,下载 安装android-ndk开发包 NDK各个版本链接二,新建项目NDKDemo,选择空Activity就可以:(注:Android studio 2.2,可通过SDK Tools 添加LLD ...
- 浅尝辄止——使用ActiveX装载WPF控件
1 引言 使用VC编写的容器类编辑器,很多都可以挂接ActiveX控件,因为基于COM的ActiveX控件不仅封装性不错,还可以显示一些不错的界面图元. 但是随着技术不断的进步,已被抛弃的Active ...
- Go Data Structures: Interfaces
refer:http://research.swtch.com/interfaces Go Data Structures: Interfaces Posted on Tuesday, Decembe ...
- Linux Overflow Vulnerability General Hardened Defense Technology、Grsecurity/PaX
Catalog . Linux attack vector . Grsecurity/PaX . Hardened toolchain . Default addition of the Stack ...
- C++ compile issue
You can do so via right-click -> Properties on a file or a selection of files in Solution Explore ...
随机推荐
- mysql5.7版本tar包手动安装---redhat7.0
1.官网下载安装包,删除系统自带的mariadb,查到几个包,卸载几个包,总之得删除干净 [root@localhost Desktop]# yum list | grep mariadb maria ...
- 从零开始搭建Webpack+react框架
1.下载node.js Node.js官网下载 , 安装: 安装成功后在控制台输入node -v 可查看当前版本: $ node -v v10.15.0 输入npm -v查看npm版本: $ npm ...
- 13、属性的get(存)和set(取)器
原因:当对年龄重新进行赋值的时候就会调用set方法,然后进行判断,如果赋值小于10就会抛出异常.
- html5 的存储
html5提供了很多存储的功能,诸如localStorage,sessionStorage,indexedDB,还有离线缓存等,本次主要介绍离线缓存跟本地存储. 离线缓存 使用离线存储可以缓存部分文 ...
- 解决Eclipse中.properties文件中文乱码问题
在.properties文件写注释时,发现中文乱码了,由于之前在idea中有见设置.properties文件的编码类型,便找了找乱码原因 在中文操作系统中,Eclipse中的Java类型文件的编码的默 ...
- sqlparameters
1.数据访问层 using的用法: 01.可以using System;导命名控空间 02.using 的语法结构 using(变量类型 变量名 =new 变量类型()) { } 案例: 03.us ...
- iSlide——图标库、图示库的用法
iSlide中,有一个“图示库”功能,主要功能是同时排列多块文字或多张图片.单击插图库,会弹出一个新的对话框.从中,可以选择权限.分类.数量数据和样式,也可以直接搜索. 下面就举一个例子:我要开一 ...
- Rhino学习教程——1.2
实战——创建个性化工具栏: 因为我们的制图习惯不同,所以可以吧自己常用的工具放在一起.我上次说的自定义界面就是这个和调整工具栏位置. 1.打开常用>设置 2.选择工具列>编辑>新增工 ...
- 关于GitHub
gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub 对于程序员来说就相当于一个仓库可以把自己写的东西放到网上 要想使用GitHub必须 ...
- presto 判断数据量是否大于一个比较小的值的优化
问题来源于以下场景: 我们需要对一张数据表做导出文件操作,需要判断如果数据量不多的时候,直接导出提供下载,如果数据量超过一定数值,则异步处理导出和下载. 这里就引入一个问题,如果我们直接count一张 ...