| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #ifndef INCLUDE_SINGLETON_POOL_HPP | |||
| 2 | #define INCLUDE_SINGLETON_POOL_HPP | |||
| 3 | ||||
| 4 | #include <memory_resource> | |||
| 5 | ||||
| 6 | namespace crts | |||
| 7 | { | |||
| 8 | ||||
| 9 | template <typename ElementType> | |||
| 10 | struct SingletonPool | |||
| 11 | { | |||
| 12 | private: | |||
| 13 | ||||
| 14 | std::pmr::monotonic_buffer_resource mbr; | |||
| 15 | std::pmr::polymorphic_allocator<ElementType> pa; | |||
| 16 | 1 | SingletonPool(): | ||
| 17 | pa{ &mbr } {}; | |||
| 18 | ||||
| 19 | public: | |||
| 20 | ||||
| 21 | 43 | static SingletonPool<ElementType>& instance() | ||
| 22 | { | |||
| 23 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
44 | static SingletonPool<ElementType> instance{}; | |
| 24 | 43 | return instance; | ||
| 25 | } | |||
| 26 | ||||
| 27 | 43 | static ElementType* malloc() { return SingletonPool<ElementType>::instance().pa.allocate(sizeof(ElementType)); } | ||
| 28 | ||||
| 29 | static void free(ElementType* /*element*/) {}; | |||
| 30 | }; | |||
| 31 | ||||
| 32 | } // namespace crts | |||
| 33 | #endif // INCLUDE_SINGLETON_POOL_HPP | |||
| 34 |