Lluvia
MemoryFreeSpaceManager.h
Go to the documentation of this file.
1 
8 #ifndef LLUVIA_CORE_MEMORY_MEMORY_FREE_SPACE_MANAGER_H_
9 #define LLUVIA_CORE_MEMORY_MEMORY_FREE_SPACE_MANAGER_H_
10 
11 #include <memory>
12 #include <ostream>
13 #include <tuple>
14 #include <vector>
15 
17 
19 
20 namespace ll {
21 namespace impl {
22 
25  uint32_t index;
26  };
27 
29 
30  public:
34  MemoryFreeSpaceManager(const uint64_t tSize);
35 
37 
40 
41  friend std::ostream& operator<<(std::ostream& out, const MemoryFreeSpaceManager& manager);
42 
43  uint64_t getSize() const noexcept;
44  uint64_t getFreeSpaceCount() const noexcept;
45 
46  const std::vector<uint64_t>& getOffsetVector() const noexcept;
47  const std::vector<uint64_t>& getSizeVector() const noexcept;
48 
49  bool allocate(uint64_t tSize, ll::MemoryAllocationInfo& out) noexcept;
50  bool allocate(uint64_t tSize, uint64_t alignment, ll::MemoryAllocationInfo& out) noexcept;
51  void release(const ll::MemoryAllocationInfo& info) noexcept;
52 
53  bool reserveManagerSpace() noexcept;
54  bool tryAllocate(uint64_t tSize, ll::impl::MemoryAllocationTryInfo& tryInfoOut) noexcept;
55  bool tryAllocate(uint64_t tSize, uint64_t alignment, ll::impl::MemoryAllocationTryInfo& tryInfoOut) noexcept;
56  void commitAllocation(const ll::impl::MemoryAllocationTryInfo& tryInfo) noexcept;
57 
58  private:
59  uint64_t m_size {0};
60 
61  // separate offset and size vectors help to keep data locality
62  // when scanning for inserting or deleting a new interval.
63  std::vector<uint64_t> m_offsetVector;
64  std::vector<uint64_t> m_sizeVector;
65  };
66 
67 } // namespace impl
68 } // namespace ll
69 
70 #endif // LLUVIA_CORE_MEMORY_MEMORY_FREE_SPACE_MANAGER_H_
Structures and methods for storing memory allocation information.
Definition: MemoryFreeSpaceManager.h:28
void release(const ll::MemoryAllocationInfo &info) noexcept
const std::vector< uint64_t > & getOffsetVector() const noexcept
MemoryFreeSpaceManager(MemoryFreeSpaceManager &&m)=default
void commitAllocation(const ll::impl::MemoryAllocationTryInfo &tryInfo) noexcept
MemoryFreeSpaceManager & operator=(MemoryFreeSpaceManager &&heap)=default
const std::vector< uint64_t > & getSizeVector() const noexcept
uint64_t getSize() const noexcept
MemoryFreeSpaceManager(const MemoryFreeSpaceManager &m)=default
uint64_t getFreeSpaceCount() const noexcept
MemoryFreeSpaceManager & operator=(const MemoryFreeSpaceManager &heap)=default
bool tryAllocate(uint64_t tSize, ll::impl::MemoryAllocationTryInfo &tryInfoOut) noexcept
MemoryFreeSpaceManager(const uint64_t tSize)
friend std::ostream & operator<<(std::ostream &out, const MemoryFreeSpaceManager &manager)
bool allocate(uint64_t tSize, ll::MemoryAllocationInfo &out) noexcept
Definition: Buffer.h:28
Structure to hold the allocation information of objects in memory.
Definition: MemoryAllocationInfo.h:19
Definition: MemoryFreeSpaceManager.h:23
ll::MemoryAllocationInfo allocInfo
Definition: MemoryFreeSpaceManager.h:24
uint32_t index
Definition: MemoryFreeSpaceManager.h:25