【发布时间】:2020-09-12 18:31:42
【问题描述】:
来自 Folly 文档
Small strings (<= 23 chars) are stored in-situ without memory allocation.
Medium strings (24 - 255 chars) are stored in malloc-allocated memory and copied eagerly.
Large strings (> 255 chars) are stored in malloc-allocated memory and copied lazily.
这些“小字符串”存储在哪里?
【问题讨论】:
-
不能肯定地说,但很可能他们的意思是他们使用对象本身的胆量,比如实际字符串成员和 char 数组的联合,并且他们使用 char 数组直到字符串增长,然后切换到使用字符串成员并分配。
-
听起来像是 Folly 版本的小字符串优化(又名 SSO):stackoverflow.com/questions/10315041/…