2
3
4
5
12
13
14
15
22
23
27
28
32
33
34
38
39
40
44
45
46
50
51
52
53 bool empty()
const {
return m_UseCount == 0; }
56
57
58
62
63
64
65
71
72
76
77
81
82
86
87
91
92
108 if (m_UseCount == 0)
return;
111
112
119 if (m_SpareCount != 0)
121 *
m_End = std::move(element);
131 const size_t bytes =
sizeof(T) * m_ExpandRate;
134 m_SpareCount = m_ExpandRate - 1;
136 m_Begin =
static_cast<T*>(malloc(bytes));
139 *
m_End = std::move(element);
145 const size_t ob =
sizeof(T) * m_UseCount;
146 const size_t nb =
sizeof(T) * m_UseCount * m_ExpandRate;
147 m_SpareCount = (nb - ob) /
sizeof(T);
149 m_Begin =
static_cast<T*>(malloc(nb));
150 memset(m_Begin, 0, nb);
151 memcpy(m_Begin, om, ob);
153 m_End =
reinterpret_cast<T*>(
reinterpret_cast<
char*>(m_Begin) + ob);
154 *
m_End = std::move(element);
168 assert(index < m_UseCount);
170 return *(
reinterpret_cast<T*>(
reinterpret_cast<
char*>(m_Begin) +
sizeof(T) * index));
CentralCache()=default
Constructor Function.
static scl::span * GetOneSpan(scl::span_list &list, size_t size)
Get a not empty span.
size_t FetchRange(void *&start, void *&end, size_t batchNum, size_t size)
Fetch range memory to tc.
static CentralCache m_CentralCache
Single instance of this.
CentralCache & operator=(const CentralCache &)=delete
Copy Assignment Operation.
virtual ~CentralCache()=default
Destructor Function.
void ReleaseListToSpans(void *start, size_t size)
Release memory to pc.
std::array< scl::span_list, MemoryPool::FREE_LIST_NUM > m_SpanLists
FreeList Array.
CentralCache(const CentralCache &)=delete
Copy Constructor Function.
static CentralCache * Get()
Get this single Instance.
Central memory cache. Second level of memory allocator.
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
void * GetFreeList() const
Get FreeList.
ObjectPool & operator=(const ObjectPool &)=delete
Copy Assignment Operation.
std::mutex m_Mutex
Mutex for thread safety.
void * m_FreeList
freelist.
scl::vector< void * > m_Memories
This objectPoll allocated memories.
void Delete(T *obj)
Free a obj of T.
virtual ~ObjectPool()
Destructor Function.
T * New()
Alloc a memory block to store T.
size_t GetNMemoryBlocks() const
Get number of memory blocks allocated to this objectPool.
size_t m_ExpandBytes
Expand bytes.
size_t m_SpareBytes
Spare bytes of this objectPool.
void * GetPointer() const
Get objectPool current memory pointer.
size_t GetSpareBytes() const
Get SpareBytes.
char * m_pointer
objectPool current memory pointer.
ObjectPool(ObjectPoolSizeMode mode=ObjectPoolSizeMode::FixedSize, size_t size=DefaultExpandKBytes)
Constructor Function.
T * ThreadNew()
Thread Safe Version of New.
ObjectPool(const ObjectPool &)=delete
Copy Constructor Function.
void ThreadDelete(T *obj)
Thread Safe Version of Delete.
static constexpr size_t DefaultExpandKBytes
use 128KB as default expand bytes.
ObjectPool Class. Specific situation(Fixed size of block) of MemoryPool.
scl::radix_trie< 64 - MemoryPool::PAGE_SHIFT, 3 > m_IdSpanMap
radix trie for [pageId - span]
virtual ~PageCache()=default
Destructor Function.
PageCache & operator=(const PageCache &)=delete
Copy Assignment Operation.
static PageCache m_PageCache
this single instance.
PageCache()=default
Constructor Function.
scl::span * MapObjectToSpan(void *obj) const
Find span by memory pointer.
scl::span * InternalNewSpan(size_t k)
Fetch pages span(internal call).
static PageCache * Get()
Get this single instance.
void ReleaseSpanToPageCache(scl::span *s)
Release span from cc to pc,.
std::mutex m_Mutex
mutex for pc.
scl::span * NewSpan(size_t k)
Fetch pages span.
ObjectPool< scl::span > m_SpanPool
ObjectPool for span.
PageCache(const PageCache &)=delete
Copy Constructor Function.
std::array< scl::span_list, MemoryPool::PAGE_NUM > m_SpanLists
FreeList Array.
Page memory cache. Third level of memory allocator.
radix_trie()
Constructor Function.
void * get(size_t k) const
Get item by key.
static constexpr size_t LENGTH
array length.
void set(size_t k, void *v)
Set pair of key - value.
virtual ~radix_trie()
Deconstruct Function.
virtual ~radix_trie()
Deconstruct Function.
void * get(size_t k) const
Get item by key.
static constexpr size_t ROOT_BITS
root bits.
static constexpr size_t LEAF_BITS
leaf bits.
radix_trie()
Constructor Function.
void set(size_t k, void *v)
Set pair of key - value.
static constexpr size_t LEAF_LENGTH
leaf array length.
Spices::ObjectPool< Leaf > m_LeafPool
ObjectPool of Leaf.
static constexpr size_t ROOT_LENGTH
root array length.
static constexpr size_t LEAF_LENGTH
leaf array length.
radix_trie()
Constructor Function.
void * get(size_t k) const
Get item by key.
void set(size_t k, void *v)
Set pair of key - value.
virtual ~radix_trie()=default
Deconstruct Function.
static constexpr size_t INTERIOR_LENGTH
interior array length.
Spices::ObjectPool< Leaf > m_LeafPool
ObjectPool of Leaf.
static constexpr size_t INTERIOR_BITS
interior bits.
Spices::ObjectPool< Node > m_NodePool
ObjectPool of Node.
static constexpr size_t LEAF_BITS
leaf bits.
void PushFront(span *s)
Push a span to this list.
span * Begin() const
Get begin pointer.
span * End() const
Get end pointer.
Bidirectional cyclic linked list for span.
void * m_FreeList
current pointer.
bool m_IsUse
True if in use.
Used for manage multiple page memory.
vector()
Constructor Function.
T * End() const
Get vector End Pointer.
size_t size() const
Get vector size.
bool empty() const
Determine if vector is empty. @retrun Returns true if empty.
virtual ~vector()
Destructor Function.
size_t m_UseCount
vector used size.
T * m_Begin
Vector Begin Pointer.
T * Begin() const
Get vector Begin Pointer.
T & get(size_t index)
Get element by index.
size_t m_ExpandRate
Vector expand rate.
size_t m_SpareCount
vector spare size.
T * m_End
Vector End Pointer.
void push_back(T &element)
Push a element in the end of vector.
This Class is similar to std::vector, the difference between that is this one allocates memory by mal...
ObjectPoolSizeMode
enum of ObjectPool expand mode
std::array< void *, LENGTH > values
std::array< void *, LEAF_LENGTH > values
std::array< Node *, ROOT_LENGTH > ptrs
std::array< void *, LEAF_LENGTH > values
std::array< Node *, INTERIOR_LENGTH > ptrs