3 回答
TA贡献2041条经验 获得超4个赞
背景/概况
malloc
/ new
new
std::string
new char [size]
std::string
char [20]
new
实施细节
std::string
大小 容量 数据的位置
std::string::size_type
size
size_type
end
你不用付钱。
class string {public: // all 83 member functionsprivate: std::unique_ptr<char[]> m_data; size_type m_size; size_type m_capacity; std::array<char, 16> m_sso;};
std::string
m_size <= 16
m_sso
m_size > 16
m_sso
class string {public: // all 83 member functionsprivate: size_type m_size; union { class { // This is probably better designed as an array-like class std::unique_ptr<char[]> m_data; size_type m_capacity; } m_large; std::array<char, sizeof(m_large)> m_small; };};
- 3 回答
- 0 关注
- 606 浏览
添加回答
举报