Boost 池的地图?

发布于 2024-08-13 08:51:51 字数 985 浏览 5 评论 0原文

基本上,我对集中内存管理的尝试非常微弱。无论如何,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花浅忆 2024-08-20 08:51:51

您是否使用 [] 运算符插入地图?这要求data_type(在本例中为boost::pool)是默认可构造的,即它必须有一个不带参数的默认构造函数。但是boost::pool没有默认的构造函数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文