在释放的 unsynchronized_pool_resource 上再次调用 allocate() 是否是未定义的行为?

问题描述 投票:0回答:0

我目前正在学习 unsynchronized_pool_resource 的行为。所以我有这个示例代码

std::pmr::monotonic_buffer_resource buffer_resource{std::pmr::new_delete_resource()}; //monotonic wrapper raw memory get from new_delete_resource
std::pmr::unsynchronized_pool_resource midlevel{&buffer_resource}; //2nd pool
std::pmr::unsynchronized_pool_resource un_sync{&midlevel}; //3rd pool
std::pmr::polymorphic_allocator<MyClass> allocator{&un_sync}; //allocator get memory from 3rd pool

MyClass* t = allocator.allocate(1);
allocator.construct(t, 20);
allocator.destroy(t);

un_sync.release(); //release

MyClass* ttt = allocator.allocate(1); //call allocate on released memory resources 
allocator.construct(ttt, 40);
allocator.destroy(ttt);

工作正常,经过我的测试,第三个池似乎是从第二个池重新构建池。我没有找到任何关于此行为的明确(或我没有看到)信息。所以在发布的

allocate()
上再次调用
unsynchronized_pool_resource
是不是未定义的行为?

c++ memory allocator c++pmr
© www.soinside.com 2019 - 2024. All rights reserved.