Native strings have tail-allocated storage, which begins at an offset of nativeBias from the storage object's address. String literals, which reside in the constant section, are encoded as their start address minus nativeBias, unifying code paths for both literals ("immortal native") and native strings. Native Strings are always managed by the Swift runtime.

即字符串数据从内部_object的起始位置加上一个偏移处起始。
对应的类是__StringStorage

内存布局如下

在 OC runtime下,是 NSString 的子类。

子类化NSString

根据文档,提供了几个方法

  @objc(length)
final internal var length: Int {
@_effects(readonly) @inline(__always) get {
return asString.utf16.count // UTF16View special-cases ASCII for us.
}
}
  @objc(characterAtIndex:)
@_effects(readonly)
final internal func character(at offset: Int) -> UInt16 {
let str = asString
return str.utf16[str._toUTF16Index(offset)]
} @objc(getCharacters:range:)
@_effects(releasenone)
final internal func getCharacters(
_ buffer: UnsafeMutablePointer<UInt16>, range aRange: _SwiftNSRange
) {
_getCharacters(buffer, aRange)
}

Swift里字符串(五)Native strings的更多相关文章

  1. Swift 里字符串(四)large sting

    对于普通的字符串,对应的_StringObject 有两个存储属性: _countAndFlagsBits: UInt64 _object: Builtin.BridgeObject _countAn ...

  2. Swift 里字符串(一)概览

    感受一下字符串相关的源文件个数  String 概览 是一个结构体 只有一个变量,类型是 _StringGuts  如上所示,String 真正的内容在__StringStorage或者__Sha ...

  3. Swift里字符串(六)Shared strings

    Shared strings do not have tail-allocated storage, but can provide access upon query to contiguous U ...

  4. Swift 里字符串(十)修改字符串

    以append操作为例 public mutating func append(_ other: String) { if self.isEmpty && !_guts.hasNati ...

  5. [Swift]LeetCode43. 字符串相乘 | Multiply Strings

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1and  ...

  6. Swift 里字符串(七)stringIndex

    在 String 里,用来索引 Character 的,不是整数,而是StringIndex 内部结构 extension String { /// A position of a character ...

  7. Swift 里字符串(三)small String

     small string, 只有两个 UInt64 的字,这里面存储了所有的信息. 内存布局如下:  第二个 UInt64 存储了标记位和长度信息,以及部分字符串的值 // Get an int ...

  8. [Swift]LeetCode415. 字符串相加 | Add Strings

    Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...

  9. Swift 里字符串(九)UTF16View

    即以 UTF16 编码的格式来查看字符串. UTF16View 是一个结构体 @_fixed_layout public struct UTF16View { @usableFromInline in ...

随机推荐

  1. maven 编译的时候总是报一些奇怪的错误 比如 surefire-boot 2.10 .jar 可是私服里查看本来就没有这个高的版本。

    或者私服总是 报 read time out , 或者  io 错误,  或者 gzip 解压错误,或者总是尝试下载一些高版本的jar , 而这些jar 可能是不存在的 .. 尝试 重新下载 apac ...

  2. iCn3D结构查看器的实现方法

    iCn3D Structure Viewer:iCn3D结构查看器 演示效果如下: 上面只是一个Basic UI的演示,如果要Advanced UI的话可以去NCBI官网看API

  3. IntelliJ IDEA 2017版 SpringBoot的核心配置详解

    Spring Boot的核心   (1)Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的Java应用程序的入口方法.  (2)@Spri ...

  4. deploy myeclipse j2ee project to server 按了没反应 怎么办

    解决办法: 1.如果工作空间的问题,那么需要删除你工作空间的一个文件就可以解决了. 这个文件在Myeclipse工作区(workspace) .metadata\.plugins\org.eclips ...

  5. C语言中交换两个数值的方法

    //方法1    int  one = 1;    int two = 2;    int temp = 0;    temp = one;    one = two;    two = temp;  ...

  6. tensorflow1.12 cuda10 cudnn7

    https://download.csdn.net/download/giselite/10909984 https://blog.csdn.net/chary8088/article/details ...

  7. 对比手机SLAM和机器人SLAM

    陀螺仪?? IMU?? 加速度器与?? 人与机器 惯性定位与?? 步骤上对比Project Tango与SLAM

  8. 日志记录的作用和方法 java

    程序中记录日志一般有两个目的:Troubleshooting和显示程序运行状态.好的日志记录方式可以提供我们足够多定位问题的依据.日志记录大家都会认为简单,但如何通过日志可以高效定位问题并不是简单的事 ...

  9. Android ADB命令基本常用操作

    电脑配置好环境变量之后呢,在cmd里面自测一下,是否配置OK: 1.查看目前连接的设备: adb devices 2.使目前连接的设备重启: adb reboot 3.有时候由于设备冲突导致adb出现 ...

  10. spring 注解实例

    先不说网上的那些例子了,百度到的都是一些零碎的东西.我之所以记博客,除了总结之外,很大一个原因是对网上的某些东西真的很无语. 拿注解来说,什么入门实例的东西,说是入门,却连一个基本的hello wor ...