1 /// 2 /// @file MemoryPool.hpp 3 /// 4 /// Copyright (C) 2020 Kim Walisch, <kim.walisch@gmail.com> 5 /// 6 /// This file is distributed under the BSD License. See the COPYING 7 /// file in the top level directory. 8 /// 9 10 #ifndef MEMORYPOOL_HPP 11 #define MEMORYPOOL_HPP 12 13 #include "Bucket.hpp" 14 #include "macros.hpp" 15 16 #include <memory> 17 #include <vector> 18 19 namespace primesieve { 20 21 class MemoryPool 22 { 23 public: 24 NOINLINE void addBucket(SievingPrime*& sievingPrime); 25 void freeBucket(Bucket* bucket); 26 27 private: 28 void allocateBuckets(); 29 void initBuckets(void* memory, std::size_t bytes); 30 void increaseAllocCount(); 31 /// List of empty buckets 32 Bucket* stock_ = nullptr; 33 /// Number of buckets to allocate 34 std::size_t count_ = 64; 35 /// Pointers of allocated buckets 36 std::vector<std::unique_ptr<char[]>> memory_; 37 }; 38 39 } // namespace 40 41 #endif 42