Home

Swift 内存管理

引用计数结构 之前我们分析过了 Swift 实例的内存结构如下: 现在我们继续分析 refCounts InlineRefCounts HeapObject 结构如下: struct HeapObject { /// This is always a valid pointer to a metadata object. HeapMetadata const *metadata; SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS; #ifndef __swift__ HeapObject() = default; // Initialize a HeapObject header as appropriate for a new...

Read more

Swift 指针

Swift 指针 Swift 中的指针分为两类: typed pointer: 指定数据类型指针,在 Swift 表示 **UnsafePointer**; raw pointer: 未指定数据类型的指针,在 Swift 表示 UnsafeRawPointer; Swift 中的指针和 OC 中的对应如下: Swift Objc 说明 unsafePointer const T * 指针和所指向的内容都不可变 unsafeMutablePointer T * 指针以及其所指向的内容均可变 ...

Read more

Swift 对象方法

类声明中的方法是通过 V-table 来进行调度的 V-table 在 SIL 中是如下表示的: decl ::= sil-vtable sil-vtable ::= 'sil_vtable' identifier '{' sil-vtable-entry* '}' sil-vtable-entry ::= sil-decl-ref ':' sil-linkage? sil-function-na me 如下示例代码 class Subject { var age: Int = 15 var name: String = "小明" func method0() -> Void { print("method0")} func method...

Read more

Swift 结构体

结构体的一些特性 如下示例代码: struct Teacher { var age: Int var name: String } 如下: 查看 SIL 码: struct Teacher { @_hasStorage var age: Int { get set } @_hasStorage var name: String { get set } init(age: Int, name: String) } 自动帮你实现了带有初始化参数的方法。 假如都有初始值的情况: struct Teacher { var age: Int = 18 var name: String = "liming" } let t = T...

Read more

Swift 对象、类和属性

实例对象的结构 class Teacher { var age: Int = 18; var name: String = "erge"; } var t = Teacher(); 初始化的时候汇编调用如下: SwiftDemo`Teacher.__allocating_init(): 0x100003c90 <+0>: pushq %rbp 0x100003c91 <+1>: movq %rsp, %rbp 0x100003c94 <+4>: pushq %r13 0x100003c96 <+6>: pushq %rax 0x100003c97 <...

Read more

Welcome

If you see this page, that means you have setup your site. enjoy! :ghost: :ghost: :ghost: You may want to config the site or writing a post next. Please feel free to create an issue or send me email if you have any questions.

Read more