【问题标题】:Binding an allocator to a custom token将分配器绑定到自定义令牌
【发布时间】:2023-02-20 20:56:53
【问题描述】:

我想知道如何将分配器绑定到我的自定义令牌并在令牌的 async_result 实现中使用它?

如果我们以use_tuple为例,它似乎只适用于它自己的use_tuple.rebind(another_allocator)分配器,而不适用于用户关联的分配器或调用异步函数的对象?

在我自己的未来类型中,我想能够说

async_read(socket, buffer, bind_allocator(some_polymorphic_alloc, my::use_future));

在 my_use_future 的 async_result<my::use_future_t, Signature> 专业化中,我想使用绑定分配器。对于 bind_allocator,async_read 函数使用该分配器进行分配。但是我没有看到分配器在其 async_result<>::initiate 函数中传递到我的 my::use_future 令牌的路径。

【问题讨论】:

    标签: c++ boost asio


    【解决方案1】:

    要将分配器绑定到自定义令牌并在令牌的 async_result 实现中使用它,您需要将分配器传递给令牌构造函数并将其存储在令牌中。然后,当创建 async_result 对象时,您可以将存储的分配器传递给启动函数。

    【讨论】:

      猜你喜欢
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 2016-11-02
      • 2018-01-15
      相关资源
      最近更新 更多