ev-stdexec-pmr-monotonic-upstream-003¶
| 字段 | 值 |
|---|---|
| 项目 | NVIDIA/stdexec |
| 固定 commit | 6d7ad689f4d4 |
| 路径 | include/nvexec/detail/memory.cuh |
| 行段 | L252-L260 |
| 特性 | 多态内存资源(std::pmr) |
| 许可证 | Apache-2.0 |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-26 |
| 测试代码 | 否 |
| 发现方式 | manual |
用法¶
让单调缓冲资源按块向上游 memory_resource 申请内存
为什么典型¶
上游资源可替换,单调资源只负责块管理与对齐,体现 pmr 的组合方式。
摘录¶
monotonic_buffer_resource(std::size_t bytes, std::pmr::memory_resource* upstream)
: upstream(upstream)
, space(STDEXEC::__umax({bytes, std::size_t{2}}))
{
block_descriptor first_block{.ptr = upstream->allocate(space, block_alignment),
.total = space};
current_ptr = first_block.ptr;
allocated_blocks.push_back(first_block);
}
备注¶
生产路径;构造函数通过 upstream->allocate 获取首块。