SpiecsEngine
 
Loading...
Searching...
No Matches
ThrealCache.h
Go to the documentation of this file.
1/**
2* @file ThrealCache.cpp.
3* @brief The ThreadCache Class Definitions.
4* @author tcmalloc.
5*/
6
7#pragma once
8#include "Core/Core.h"
9#include "MemoryPool.h"
10#include "Core/Container/FreeList.h"
11
12namespace Spices {
13
14 /**
15 * @brief Thread memory cache.
16 * First level of memory allocator.
17 */
19 {
20 public:
21
22 /**
23 * @brief Constructor Function.
24 */
25 ThreadCache() = default;
26
27 /**
28 * @brief Destructor Function.
29 */
30 virtual ~ThreadCache();
31
32 /**
33 * @brief Copy Constructor Function.
34 * @note This Class not allowed copy behaves.
35 */
36 ThreadCache(const ThreadCache&) = delete;
37
38 /**
39 * @brief Copy Assignment Operation.
40 * @note This Class not allowed copy behaves.
41 */
42 ThreadCache& operator=(const ThreadCache&) = delete;
43
44 /**
45 * @brief Allocate memory.
46 * @param[in] size memory bytes.
47 * @return Returns memory pointer.
48 */
49 void* Allocate(size_t size);
50
51 /**
52 * @brief Recycle object memory.
53 * @param[in] obj object pointer.
54 * @param[in] size object bytes.
55 */
56 void Deallocate(void* obj, size_t size);
57
58 private:
59
60 /**
61 * @brief Release memory to cc.
62 * @param[in] list free_list.
63 * @param[in] size object bytes.
64 * @param[in] count release count.
65 */
66 static void ReleaseToCentralCache(scl::free_list& list, size_t size, size_t count);
67
68 /**
69 * @brief Fetch memory from central cache if this is run out.
70 * @param[in] index freelist index.
71 * @param[in] alignSize align up bytes.
72 * @return Returns memory pointer.
73 */
74 void* FetchFromCentralCache(size_t index, size_t alignSize);
75
76 private:
77
78 /**
79 * @brief FreeList Array.
80 */
82 };
83
84 /**
85 * @brief Wapper of Instance/Delete ThreadCache in thread.
86 */
88 {
89 public:
90
91 /**
92 * @brief Constructor Function.
93 */
95
96 /**
97 * @brief Destructor Function.
98 */
99 virtual ~ThreadCacheThreadWapper();
100
101 /**
102 * @brief Get ThreadCache Instance.
103 * @reutrn Returns ThreadCache Instance.
104 */
105 static ThreadCache*& GetInst();
106
107 private:
108
109 /**
110 * @brief This thread ThreadCache instance.
111 */
113 };
114}
static void Free(void *ptr)
Free memory entry point.
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
MemoryPool Class.
Definition MemoryPool.h:22
scl::span * MapObjectToSpan(void *obj) const
Find span by memory pointer.
Definition PageCache.cpp:21
static PageCache * Get()
Get this single instance.
Definition PageCache.h:50
void ReleaseSpanToPageCache(scl::span *s)
Release span from cc to pc,.
Definition PageCache.cpp:43
Page memory cache. Third level of memory allocator.
Definition PageCache.h:21
virtual ~ThreadCacheThreadWapper()
Destructor Function.
ThreadCache * instance
This thread ThreadCache instance.
ThreadCacheThreadWapper()
Constructor Function.
Definition ThrealCache.h:94
static ThreadCache *& GetInst()
Get ThreadCache Instance. @reutrn Returns ThreadCache Instance.
Wapper of Instance/Delete ThreadCache in thread.
Definition ThrealCache.h:88
void Deallocate(void *obj, size_t size)
Recycle object memory.
ThreadCache & operator=(const ThreadCache &)=delete
Copy Assignment Operation.
void * FetchFromCentralCache(size_t index, size_t alignSize)
Fetch memory from central cache if this is run out.
std::array< scl::free_list, MemoryPool::FREE_LIST_NUM > m_FreeLists
FreeList Array.
Definition ThrealCache.h:81
static void ReleaseToCentralCache(scl::free_list &list, size_t size, size_t count)
Release memory to cc.
virtual ~ThreadCache()
Destructor Function.
ThreadCache(const ThreadCache &)=delete
Copy Constructor Function.
void * Allocate(size_t size)
Allocate memory.
ThreadCache()=default
Constructor Function.
Thread memory cache. First level of memory allocator.
Definition ThrealCache.h:19
Free list for memory pool.
Definition FreeList.h:16
bool m_IsUse
True if in use.
Definition SpanList.h:61
Used for manage multiple page memory.
Definition SpanList.h:15