您的位置:首页 > 移动开发 > Objective-C

什么情况下应该使用对象池(ObjectPool)?

2011-11-05 17:09 507 查看
对象池很多时候是很有用的模式,有时甚至是必须。但凡事过犹不及,对象池也只有在一些场景下才适合。

Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instances in use at any one time is low. The pooled object is obtained in predictable time when creation of the new objects (especially over network) may take variable time.

However these benefits are mostly true for objects which are expensive with respect to time, such as database connections, socket connections, threads and large graphic objects like fonts or bitmaps. In certain situations, simple object pooling (which hold no external resources, but only occupy memory) may not be efficient and could decrease performance.
引用自:
http://en.wikipedia.org/wiki/Object_pool_pattern

References

http://www.ibm.com/developerworks/java/library/j-jtp09275/index.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: