"in-situ without memory allocation" 对于 String 的愚蠢实现意味着什么?

What does "in-situ without memory allocation" mean for folly implementation of String?

来自 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.

这些 "Small String" 存储在哪里?

这意味着std::string的成本已经包含了23个字符。更多的需要额外分配。

这意味着内部结构大致如下:

struct string {
  // ...
  char internal[23];
  char* external;
};

这大概是为了让复制短字符串变得非常便宜,因为不需要执行堆操作,而且它不需要任何 delete 调用来清除。