-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_pool.h
67 lines (58 loc) · 1.27 KB
/
memory_pool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _INCLUDED_MEMORY_POOL_H_
#define _INCLUDED_MEMORY_POOL_H_
#include <stdio.h>
#include "types.h"
/*
MEMORY_POOL_BLOCK構造体
メモリプールの個別ブロック
*/
typedef struct _MEMORY_POOL_BLOCK
{
void *data; // データ
struct _MEMORY_POOL_BLOCK *next; // 次のブロック
} MEMORY_POOL_BLOCK;
/*
MEMORY_POOL構造体
要求サイズに応じたメモリアドレスを返す
(個別の開放はできない)
*/
typedef struct _MEMORY_POOL
{
MEMORY_POOL_BLOCK *top;
MEMORY_POOL_BLOCK *current;
void *next_allocate;
void *end_of_current;
size_t block_size;
} MEMORY_POOL;
#ifdef __cplusplus
extern "C" {
#endif
/*
InitializeMemoryPool関数
メモリプールを管理するデータを初期化する
引数
pool : メモリプールを管理するデータ
block_size : メモリプールブロック1つ分のサイズ
*/
EXTERN void InitializeMemoryPool(MEMORY_POOL* pool, size_t block_size);
/*
ReleaseMemoryPool関数
メモリプール全体を開放する
引数
pool : 開放するメモリプール
*/
EXTERN void ReleaseMemoryPool(MEMORY_POOL* pool);
/*
MemoryPoolAllocate関数
メモリプールに次のメモリ確保を要求する
引数
pool : メモリプールを管理するデータ
size : 要求するメモリのバイト数
返り値
確保したメモリアドレス
*/
EXTERN void* MemoryPoolAllocate(MEMORY_POOL* pool, size_t size);
#ifdef __cplusplus
}
#endif
#endif // #ifndef _INCLUDED_MEMORY_POOL_H_