FASTHEAP.H
[目次 | 型・クラス・構造体 | マクロ]
1|/**************************************************************************
2|* 1. <<< 高速ヒープ領域 (FastHeap) >>>
3|***************************************************************************/
4|
5|#ifndef __FASTHEAP_H
6|#define __FASTHEAP_H
7|
8|
9|/*************************************************************************
10|* 2. <<< 優先ヘッダ >>>
11|**************************************************************************/
12|#ifndef USES_PRIORITY_HEADER
13|/*[START_OF_PRIORITY_HEADER]*/
14|
15|#define USES_HEAP
16|typedef struct _Heap Heap;
17|typedef struct _Heap_SizeSet Heap_SizeSet;
18|typedef struct _Heap_SizeBlk Heap_SizeBlk;
19|
20|/*[END_OF_PRIORITY_HEADER]*/
21|#endif
22|
23|/* 派生属性の設定 */
24|#if defined(HEAP_SOME)
25| #define HEAP_OTHER
26|#endif
27|
28|/*************************************************************************
29|* 3. <<< エラーコード, リターンコード >>>
30|**************************************************************************/
31|
32|#define Heap_Err_Some 0
33|
34|
35|/*--------------------------------------------------------------*/
36|/*4. <<< Interface Area -------------------------------------- >>> */
37|/*--------------------------------------------------------------*/
38|
39|#ifdef __cplusplus
40|extern "C" {
41|#endif
42|
43|
44|/**************************************************************************
45|* 5. <<< [FastHeap_Mem] 高速ヒープ領域、またはそのメモリ領域を管理する登録簿 >>>
46|***************************************************************************/
47|typedef ArrX_Able FastHeap_Mem;
48|
49|/* void* FastHeap_Mem_init( FastHeap_Mem*, void* adr, int size, type ); */
50|/* void fast_malloc( type** pptr, type ); */
51|/* void fast_free( type* ptr, type ); */
52|
53|/**************************************************************************
54|* 6. <<< [FastHeap_Book] 高速ヒープ領域のメモリ領域を管理する登録簿 >>>
55|***************************************************************************/
56|typedef ArrX_Able FastHeap_Book;
57|
58|/* void* FastHeap_Book_init( FastHeap_Book*, void* adr, int size, type ); */
59|/* void fast_malloc2( type** pptr, FastHeap_Book* book, type ); */
60|/* void fast_free2( type* ptr, FastHeap_Book* book, type ); */
61|
62|#ifdef __cplusplus
63|}
64|#endif
65|
66|/*--------------------------------------------------------------*/
67|/*7. <<< Mapping Area ---------------------------------------- >>> */
68|/*--------------------------------------------------------------*/
69|
70|
71|/**************************************************************************
72|* 8. <<< [FastHeap_Mem_init] 高速ヒープ領域を初期化する >>>
73|*【引数】
74|* ・FastHeap_Mem* 高速ヒープ領域の管理構造体のアドレス
75|* ・void* adr; 高速ヒープ領域として使用するメモリ領域の先頭アドレス
76|* ・int size; adr のメモリ領域のうち使用するサイズ(バイト)
77|* ・type; 確保開放する型
78|* ・void* 返り値; adr + size
79|*【補足】
80|*・void* FastHeap_Mem_init( FastHeap_Mem*, void* adr, int size, type );
81|***************************************************************************/
82|#define FastHeap_Mem_init( this, adr, size, type ) \
83| ( ArrX_Able_init( this, adr, size, type ), (void*)( (char*)adr + size ) )
84|
85|
86|/**************************************************************************
87|* 9. <<< [fast_malloc] 高速ヒープ領域からメモリ領域を確保する >>>
88|*【引数】
89|* ・type; 確保するメモリ領域の型
90|*【補足】
91|*・void fast_malloc( type** pptr, type );
92|***************************************************************************/
93|#define fast_malloc( pptr, type ) \
94|( \
95| *(pptr) = ArrX_Able_getFirstDisabled( &FastHeap_##type##_mem, type ), \
96| ArrX_AbleElem_setAble( *(pptr), true ) \
97|)
98|
99|
100|
101|/**************************************************************************
102|* 10. <<< [fast_free] 高速ヒープ領域のメモリ領域を開放する >>>
103|*【引数】
104|* ・void* adr; 開放するメモリ領域のアドレス
105|*【補足】
106|*・void fast_free( void* );
107|***************************************************************************/
108|#define fast_free( ptr, type ) \
109| ArrX_AbleElem_setAble( ptr, false )
110|
111|/**************************************************************************
112|* 11. <<< [FastHeap_Book_init] 高速ヒープ領域の登録簿を初期化する >>>
113|*【引数】
114|* ・FastHeap_Book* 確保したメモリ領域を登録する登録簿
115|* ・void* adr; 高速ヒープ領域として使用するメモリ領域の先頭アドレス
116|* ・int size; adr のメモリ領域のうち使用するサイズ(バイト)
117|* ・type; 確保開放する型
118|* ・void* 返り値; adr + size
119|*【補足】
120|*・void* FastHeap_Book_init( FastHeap_Book*, void* adr, int size, type );
121|***************************************************************************/
122|#define FastHeap_Book_init( this, adr, size, type ) \
123| ( ArrX_Able_init( this, adr, size, type ), (void*)( (char*)adr + size ) )
124|
125|
126|/**************************************************************************
127|* 12. <<< [fast_malloc2] 高速ヒープ領域からメモリ領域を確保し、登録簿に登録する >>>
128|*【引数】
129|* ・type** pptr; 確保したメモリ領域の先頭アドレスを格納する領域のアドレス
130|* ・FastHeap_Book* 確保したメモリ領域を登録する登録簿
131|* ・type; 確保するメモリ領域の型
132|*【補足】
133|*・void fast_malloc2( type** pptr, FastHeap_Book* book, type );
134|***************************************************************************/
135|#define fast_malloc2( pptr, book, type ) \
136|( \
137| *(pptr) = ArrX_Able_getFirstDisabled( book, type ), \
138| ArrX_AbleElem_setAble( *(pptr), true ) \
139|)
140|
141|
142|
143|/**************************************************************************
144|* 13. <<< [fast_free2] 高速ヒープ領域のメモリ領域を開放し、登録簿から消す >>>
145|*【引数】
146|* ・void* ptr; 開放するメモリ領域のアドレス
147|* ・FastHeap_Book* 確保したメモリ領域が登録してあった登録簿
148|* ・type; 確保するメモリ領域の型
149|*【補足】
150|*・void fast_free2( void* ptr, FastHeap_Book* book, type );
151|***************************************************************************/
152|#define fast_free2( ptr, book, type ) \
153| ArrX_AbleElem_setAble( ptr, false )
154|
155|#endif /* __HEAP_H */
156|
157|