与NSMutableArray里的NSArray和性能问题 [英] Performance issues with NSMutableArray and NSArray

查看:272
本文介绍了与NSMutableArray里的NSArray和性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编程的C / C ++为20年,但我是新来的Objective-C和可可和​​对的NSMutableArray和NSArray的性能的一些问题。

I've been programming C/C++ for 20 years but I'm new to objective-c and Coco and have some questions about the performance of NSMutableArray and NSArray.

我需要很像STL列表容器的容器,但可可似乎并不有一个和插入和MSMutableArray中间删除元素看起来很慢,但对待它像一个STL的vector是不是快无论是。

I need an container much like the stl list container, but coco doesn't seem to have one and inserting and removing elements from the middle of MSMutableArray seems slow, but treating it like a stl vector isn't that fast either.

此外,MSMutableArray似乎只能存储对象,所以要简单数据类型,行int的跟踪或浮动即被创建对象将它们存储在额外的开销。

Also, MSMutableArray seems to only store Objects, so keep tracking of a simple data type line int or float incurs additional overhead of creating Objects to store them in.

我目前正在写一个游戏,性能是至关重要的。我总是可以拖放到C ++为我的游戏引擎的胆量,但有这么多的Objective-C,我喜欢和我讨厌放弃它。

I'm currently writing a game and performance is critical. I can always drop into C++ for the guts of my game engine, but there is so much about objective-c that I like and I'd hate to abandon it.

是否有快速的STL像Objective-C的容器,我应该使用?

Are there fast stl like containers for objective-c that I should be using?

有没有关于如何这些实现​​的,因此我可以尝试把人物表现为何如此缓慢的任何好的在线文档?

Is there any good online documentation about how these are implemented so I can try and figure put why performance is so slow?

谢谢!

推荐答案

基础集合类一样的NSMutableArray不保证使用任何特定的实现,而事实上我相信他们会真正改变自己的数据结构来优化速度的它们包括项的数目。你可以阅读更多 rel=\"nofollow\">,但基本上我不会担心底层的算法。

The foundation collection classes like NSMutableArray aren't guaranteed to use any specific implementation, and in fact I believe they will actually change their data structure to optimize speed for the number of items they contain. You can read more here, but basically I wouldn't worry about the underlying algorithm.

您可以创建一个用C自己的数据结构(或去,如果你想要的Objective-C ++路线),这将节省每个包裹在原始的一个NSNumber的内存和性能开销。当然,你要首先运行性能工具,以确保这真的是问题所在,而你不只是浪费你的时间。

You could create your own data structure in C (or go the Objective-C++ route if you want), which would save the memory and performance overhead of wrapping each primitive in an NSNumber. Of course, you'll want to run the performance tools first to make sure this is really where the problem lies, and you're not just wasting your time.

这篇关于与NSMutableArray里的NSArray和性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆