mFrame
載入中...
搜尋中...
無符合項目
IndexedPayloadArena.h
1
7#ifndef MFRAME_6B8EAE16_5470_4A62_A67B_182F60466B41
8#define MFRAME_6B8EAE16_5470_4A62_A67B_182F60466B41
9
10/* ***************************************************************************************
11 * Include
12 */
13
14//----------------------------------------------------------------------------------------
15#include "./../lang/Memory.h"
16#include "./../lang/Object.h"
17#include "./../util/Container.h"
18
19//----------------------------------------------------------------------------------------
20
21/* ***************************************************************************************
22 * Namespace
23 */
24namespace ufm::util {
25 class IndexedPayloadArena;
26} // namespace ufm::util
27
28/* ***************************************************************************************
29 * Class/Interface/Struct/Enum
30 */
31
42 /* *************************************************************************************
43 * Class/Interface/Struct/Enum
44 */
45 public:
46 struct Handle; // 記憶體區塊控制結構,用於追蹤每個資料塊的元數據
47
48 /* *************************************************************************************
49 * Variable
50 */
51 private:
52 ufm::lang::Memory vMemory;
53 uint16 vSize;
54 uint16 vLength;
55
56 /* *************************************************************************************
57 * Abstract Method
58 */
59
60 /* *************************************************************************************
61 * Construct Method
62 */
63 public:
70
75 virtual ~IndexedPayloadArena(void) override;
76
77 /* *************************************************************************************
78 * Operator Method
79 */
80
81 /* *************************************************************************************
82 * Override - ufm::util::Container
83 */
84 public:
92 virtual void clear(void) override;
93
99 virtual bool isEmpty(void) const override;
100
108 virtual int size(void) const override;
109
110 /* *************************************************************************************
111 * Public Method
112 */
113 public:
124 template <typename T, size_t N>
125 inline bool insert(T (&array)[N], int index) {
126 return this->insert(&array[0], static_cast<int>(N * sizeof(T)), index);
127 }
128
138 bool insert(const void* data, int length, int index);
139
147 bool remove(int index);
148
156 int get(void*& data, int index) const;
157
168 template <typename T>
169 int get(T*& data, int index) const {
170 void* raw = nullptr;
171 int result = this->get(raw, index);
172 data = static_cast<T*>(raw); // 或 reinterpret_cast<T*>(raw),取決於實際需求
173 return result;
174 }
175
186 template <typename T, size_t N>
187 inline bool set(T (&array)[N], int index) {
188 return this->set(&array[0], static_cast<int>(N * sizeof(T)), index);
189 }
190
200 bool set(const void* data, int length, int index);
201
207 int availableGap(void) const;
208
217 int compact(void);
218
219 /* *************************************************************************************
220 * Public Method
221 */
222
223 /* *************************************************************************************
224 * Protected Method
225 */
226
227 /* *************************************************************************************
228 * Private Method
229 */
230
231 /* *************************************************************************************
232 * Static Variable
233 */
234 public:
235 static constexpr uint16 ELEMENT_SHIFT = 3;
236 static constexpr uint16 ELEMENT_MASK = ((1 << ELEMENT_SHIFT) - 1);
237
238 /* *************************************************************************************
239 * Static Method
240 */
241};
242
256
257/* ***************************************************************************************
258 * End of file
259 */
260
261#endif /* MFRAME_6B8EAE16_5470_4A62_A67B_182F60466B41 */
動態記憶體管理類別
Definition Memory.h:38
物件基底類別
Definition Object.h:63
索引化有效載荷記憶體區域管理器
Definition IndexedPayloadArena.h:41
bool set(const void *data, int length, int index)
設定指定索引位置的資料
bool insert(const void *data, int length, int index)
在指定索引位置插入資料
static constexpr uint16 ELEMENT_MASK
元素對齊遮罩
Definition IndexedPayloadArena.h:236
static constexpr uint16 ELEMENT_SHIFT
元素對齊位移量(8位元組對齊)
Definition IndexedPayloadArena.h:235
int availableGap(void) const
獲取可用的記憶體間隙大小
virtual int size(void) const override
返回此集合中的元素數量
bool set(T(&array)[N], int index)
設定指定索引位置的陣列資料
Definition IndexedPayloadArena.h:187
virtual void clear(void) override
從此集合中刪除所有元素(可選操作)
int get(T *&data, int index) const
獲取指定索引的資料,並轉換為指定型別指標
Definition IndexedPayloadArena.h:169
virtual ~IndexedPayloadArena(void) override
析構函數,釋放資源
int get(void *&data, int index) const
獲取指定索引的資料
int compact(void)
壓縮記憶體,整理碎片空間
bool insert(T(&array)[N], int index)
在指定索引位置插入陣列資料
Definition IndexedPayloadArena.h:125
bool remove(int index)
移除指定索引的資料塊
virtual bool isEmpty(void) const override
檢查此集合是否不包含任何元素
IndexedPayloadArena(ufm::lang::Memory memory)
建構索引化有效載荷記憶體區域管理器
Definition Iterable.h:28
容器介面,定義所有集合容器的基本操作。
Definition Container.h:176
資料塊控制結構
Definition IndexedPayloadArena.h:250
uint16 offset
資料塊在記憶體中的偏移量
Definition IndexedPayloadArena.h:253
uint16 index
資料塊的索引編號
Definition IndexedPayloadArena.h:254
uint16 capacity
資料塊的總容量(位元組)
Definition IndexedPayloadArena.h:251
uint16 length
資料塊的實際使用長度(位元組)
Definition IndexedPayloadArena.h:252