作者member (浮云)
看板C_Sharp
标题Re: [讨论] 字串
时间Fri Dec 9 12:46:31 2005
※ 引述《virdust2003 (替机壳洗个热水澡)》之铭言:
: http://www.codeproject.com/dotnet/strings.asp
: 文章中介绍的 SetLength 不知道会不会造成 Memory leaking 的问题
: 除非 GC 是使用 Capacity 去回收,但想想使用 capacity去回收也没什麽错
我不清楚 C# 的 GC 回收方式, 但应该是解构整个物件, 释放记忆体
: 还有 为什麽
: 'Good morning' has capacity 17, length 12
: 是17啊? 是加了 m_currentThread 、m_MaxCapacity 吗?
要考虑 StringBuilder 预设的 capacity 是16, 再加上 \0 就是17
文中有说 capacity 比字串大二倍以上, 才会缩减并重新建立新 string 来输出
程式是取得 string 的 m_arrayLength
int *pcapacity = (int *)p - 2;
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.104.235.206
1F:推 virdust2003:恩,忘了16 12/10 00:41