-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconst_mem_pool.c
More file actions
40 lines (27 loc) · 800 Bytes
/
const_mem_pool.c
File metadata and controls
40 lines (27 loc) · 800 Bytes
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
#include "const_mem_pool.h"
void const_mem_pool_destroy(struct const_mem_pool *p) {
}
struct const_mem_pool *const_mem_pool_create(size_t size, void *mem) {
if( size < sizeof(struct const_mem_pool) ) {
return 0;
}
size_t pool_size = size - sizeof(struct const_mem_pool);
struct const_mem_pool *pool = mem;
pool->p = &pool->data[0];
pool->pe = &pool->data[pool_size];
return pool;
}
void *const_mem_pool_alloc(void *cc, size_t size) {
struct const_mem_pool *pool = cc;
if( pool->p + size <= pool->pe ) {
void *mem = pool->p;
pool->p += size;
return mem;
}
return 0;
}
void const_mem_pool_dealloc(void *cc, void *mem) {
}
size_t const_mem_pool_avail(struct const_mem_pool *poo) {
return poo->pe - poo->p;
}