Boost 池的地图?
基本上,我对集中内存管理的尝试非常微弱。无论如何,boost::pool 使用特定大小的块。
我最初的想法是重载 new 和删除,将大小传递到一个单例中,该单例将进入相应的 boost 池并从那里分配。
std::map<size_t, boost::pool<> > m_MemPools;
无论如何,我似乎无法获得 boost 池的映射,因为 MSVC9 给了我以下错误,
:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\map(173) : error C2512: 'boost::pool<>::pool' : no appropriate default constructor available
为什么会发生这种情况?
编辑
我解决了它,我最终只是将它包装在一个shared_ptr中,这解决了问题。
只是为了展示一些东西,我不再使用 [] ,它仍然给出这个错误,
class Pooly
{
public:
Foo()
{
}
void RegisterPool(__in const size_t poolSize)
{
if(pools.find(poolSize) == pools.end())
pools.insert(std::make_pair(poolSize, boost::pool<>(poolSize)));
}
private:
std::map<size_t, boost::pool<> > pools;
};
我猜它与 std::make_pair 有关?
Etherway 将其包装为智能指针工作正常,但这不应该是应该包含在 boost 池中的东西吗?
Basically im giving a very weak shot at trying to centralize memory management. Anyways, boost::pool uses chunks of certain sizes.
My orignal idea, was to overload new and delete, pass the size into a singleton which would go to the corresponding boost pool and alloc from there.
std::map<size_t, boost::pool<> > m_MemPools;
Anyways it seems like i cannot have a map of boost pools, since it MSVC9 gives me the following error,
:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\map(173) : error C2512: 'boost::pool<>::pool' : no appropriate default constructor available
Why would this be happening?
EDIT
I solved it, i ended up just wrapping it in a shared_ptr, which resolves the issue.
Just to show something, i do not use [] anymore, and it still gives this error,
class Pooly
{
public:
Foo()
{
}
void RegisterPool(__in const size_t poolSize)
{
if(pools.find(poolSize) == pools.end())
pools.insert(std::make_pair(poolSize, boost::pool<>(poolSize)));
}
private:
std::map<size_t, boost::pool<> > pools;
};
Im guessing it has to do with std::make_pair?
Etherway wrapping it a smart pointer works fine, shouldnt this be something that should be included in boost pool though?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用
[]
运算符插入地图?这要求data_type
(在本例中为boost::pool
)是默认可构造的,即它必须有一个不带参数的默认构造函数。但是boost::pool没有默认的构造函数。Are you using the
[]
operator to insert into the map? This requires thedata_type
, in this caseboost::pool
, to be default constructible, i.e. it must have a default constructor that takes no arguments. Butboost::pool
does not have a default constructor.