@@ -33,25 +33,19 @@ namespace header
3333// / - returns a Stack ready to be shipped.
3434struct Stack {
3535
36- private:
37- static void freefn (void * data, void * hint)
38- {
39- boost::container::pmr::memory_resource* resource = static_cast <boost::container::pmr::memory_resource*>(hint);
40- resource->deallocate (data, 0 , 0 );
41- }
36+ using memory_resource = o2::pmr::memory_resource;
4237
38+ private:
4339 struct freeobj {
44- freeobj () {}
45- freeobj (boost::container::pmr::memory_resource* mr) : resource(mr) {}
46-
47- boost::container::pmr::memory_resource* resource{ nullptr };
48- void operator ()(o2::byte* ptr) { Stack::freefn (ptr, resource); }
40+ freeobj (memory_resource* mr) : resource(mr) {}
41+ memory_resource* resource{ nullptr };
42+ void operator ()(o2::byte* ptr) { resource->deallocate (ptr, 0 , 0 ); }
4943 };
5044
5145 public:
5246 using allocator_type = boost::container::pmr::polymorphic_allocator<o2::byte>;
5347 using value_type = o2::byte;
54- using BufferType = std::unique_ptr<value_type[], freeobj>;
48+ using BufferType = std::unique_ptr<value_type[], freeobj>; // this gives us proper default move semantics for free
5549
5650 Stack () = default ;
5751 Stack (Stack&&) = default ;
@@ -64,8 +58,6 @@ struct Stack {
6458 allocator_type get_allocator () const { return allocator; }
6559
6660 //
67- boost::container::pmr::memory_resource* getFreefnHint () const noexcept { return allocator.resource (); }
68- static auto getFreefn () noexcept { return &freefn; }
6961
7062 // / The magic constructors: take arbitrary number of headers and serialize them
7163 // / into the buffer buffer allocated by the specified polymorphic allocator. By default
@@ -86,15 +78,15 @@ struct Stack {
8678 : allocator{ allocatorArg },
8779 bufferSize{ calculateSize (std::forward<Headers>(headers)...) },
8880 buffer{ static_cast <o2::byte*>(allocator.resource ()->allocate (bufferSize, alignof (std::max_align_t ))),
89- freeobj (getFreefnHint ()) }
81+ freeobj (allocator. resource ()) }
9082 {
9183 inject (buffer.get (), std::forward<Headers>(headers)...);
9284 }
9385
9486 private:
9587 allocator_type allocator{ boost::container::pmr::new_delete_resource () };
9688 size_t bufferSize{ 0 };
97- BufferType buffer{ nullptr , freeobj{ getFreefnHint () } };
89+ BufferType buffer{ nullptr , freeobj{ allocator. resource () } };
9890
9991 template <typename T, typename ... Args>
10092 static size_t calculateSize (T&& h, Args&&... args) noexcept
0 commit comments