Compare the efficiency of this function with that of the destructor for a non-reference-counted implementation. Such a function would always call delete and would almost certainly have a nontrivial runtime cost. Provided that different String objects do in fact sometimes have the same values, the implementation above will sometimes do nothing more than decrement a counter and compare it to zero.
index in the grand C++ tradition, which is to say not at all. As usual, if you'd like a greater degree of parameter validation, it's easy to add.) (More effetive C++ Item29)(这个函数实现了C++传统意义上的下标索引(根本不会说“不”)。
C++字符串管理效率探讨
本文对比了引用计数和非引用计数两种实现方式在C++字符串管理中的效率。对于具有相同值的不同String对象,引用计数实现仅需递减引用计数并检查其是否为零,而非引用计数实现则总是调用delete操作,导致更高的运行时成本。
7660

被折叠的 条评论
为什么被折叠?



