您的位置:首页 > 移动开发 > Cocos引擎

找到《Learn iPhone and iPad Cocos2D Game Development》一书翻译中的一处错误

2012-06-02 23:43 204 查看
《Learn iPhone and iPad Cocos2D Game Development》一书有一段关于CCArray的描述:

CCArray通过将数组中的最后一个对象(nil)赋值给删除的位置,实现了fastRemoveObject和fastRemoveObjectAtIndex两个方法。避免了复制部份数组的内存。这让删除数组中的元素变的更快,不过这也意味着CCArray中的对象会改变位置。


cocos2d中fastRemoveObject和fastRemoveObjectAtIndex这两个方法最终都是通过下面这个函数来实现的

/** Removes object at specified index and fills the gap with the last object,
thereby avoiding the need to push back subsequent objects.
Behaviour undefined if index outside [0, num-1]. */
static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, NSUInteger index)
{
[arr->arr[index] release];
NSUInteger last = --arr->num;
arr->arr[index] = arr->arr[last];
}


很明显,最后一个对象并不是nil。翻译者画蛇添足,会造成一些读者理解上的困扰!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐