1

基本上我在尝试集中内存管理时给出了一个非常弱的镜头。无论如何, boost::pool 使用特定大小的块。

我最初的想法是重载 new 和 delete,将大小传递给一个单例,该单例将进入相应的提升池并从那里分配。

std::map<size_t, boost::pool<> > m_MemPools;

无论如何,我似乎无法拥有提升池的地图,因为它 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 pool 中的东西吗?

4

1 回答 1

1

Are you using the [] operator to insert into the map? This requires the data_type, in this case boost::pool, to be default constructible, i.e. it must have a default constructor that takes no arguments. But boost::pool does not have a default constructor.

于 2009-12-04T07:17:27.790 回答