calloc 的 boost 池替代方案
所有,
如果您使用 boost 池库,您将如何替换以下语句:
MyStruct *someStruct = (MyStruct *) calloc(numOfElements, sizeof(MyStruct));
如果它是针对一个元素,我会这样做:
boost::object_pool<MyStruct> myPool;
MyStruct *someStruct = myPool.malloc();
但由于“numOfElements”是一个变量,我感觉执行 malloc() 循环不是好主意吗?
all,
If you use boost pool library, how would you replace the following statement:
MyStruct *someStruct = (MyStruct *) calloc(numOfElements, sizeof(MyStruct));
If it was for one element, I would do:
boost::object_pool<MyStruct> myPool;
MyStruct *someStruct = myPool.malloc();
but since "numOfElements" is a variable, I have the feeling executing a loop of malloc() is not a good idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说你需要使用
pool_alloc
接口:示例来自 http://www.boost.org/doc/libs/1_47_0/libs/pool/doc/interfaces.html
I'd say you need to use
pool_alloc
interface:Sample from http://www.boost.org/doc/libs/1_47_0/libs/pool/doc/interfaces.html