对象池与动态分配 [英] Object pool vs. dynamic allocation

查看:92
本文介绍了对象池与动态分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候应该比动态分配的对象更喜欢对象池?

我需要每秒创建和销毁数千个对象.本身足以决定支持对象池吗?

谢谢.

解决方案

是的,这足以决定是否支持对象池.

引用Boost文档

我什么时候应该使用Pool?

通常在有游泳池的情况下使用游泳池 很多分配和解除分配 小物件.另一个常见用法 是上面的情况,其中很多 对象可能会掉出内存.

请参见 Boost Pool 库 >

When should one prefer object pool over dynamically allocated objects?

I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool?

Thanks.

解决方案

Yes, this is enough to decide in favor of object pool.

Quoting Boost documentation

When should I use Pool?

Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation above, where many objects may be dropped out of memory.

See Boost Pool library

这篇关于对象池与动态分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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