-
Notifications
You must be signed in to change notification settings - Fork 3
/
mem.h
57 lines (45 loc) · 1.73 KB
/
mem.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
/*
* mem.h
* Copyright (C) 2006, Tomasz Koziara (t.koziara AT gmail.com)
* --------------------------------------------------------------
* memory pool
*/
/* This file is part of Solfec.
* Solfec is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Solfec is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Solfec. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#ifndef __mem__
#define __mem__
typedef struct memory_pool MEM;
struct memory_pool
{
void *blocks; /* list of allocated memory blocks */
char *freechunk; /* next free chunk of memory */
char *lastchunk; /* last chunk in current block */
void *deadchunks; /* list of dealocated chunks of memory */
size_t chunksize; /* size of a chunk */
size_t chunksinblock; /* number of memory chunks in a block */
};
/* allocate global zero'd memory */
void* MEM_CALLOC (size_t size);
/* initialize memory pool */
void MEM_Init (MEM *pool, size_t chunksize, size_t chunksinblock);
/* allocate a chunk of memory from the pool */
void* MEM_Alloc (MEM *pool);
/* free a chunk of memory to the pool */
void MEM_Free (MEM *pool, void *chunk);
/* return amount of memory in the pool */
size_t MEM_Size (MEM *pool);
/* release memory pool memory back to system */
void MEM_Release (MEM *pool);
#endif