9 #ifndef __FN_FINALIZE_T_DEFINED
10 typedef int (*fn_finalize_t)(void**);
11 #define __FN_FINALIZE_T_DEFINED
14 #ifndef __BYTE_T_DEFINED
15 typedef unsigned char byte;
16 #define __BYTE_T_DEFINED
19 /* forward declarations */
20 struct s_allocator; /* allocator struct */
21 struct s_allocator_block; /* allocator block struct */
22 struct s_allocator_node; /* allocator node struct */
25 /* the allocator node type */
26 typedef struct s_allocator_node
28 struct s_allocator_node* next; /* the next node in the block */
29 struct s_allocator_block* block; /* the block which contains the node */
30 int is_allocated; /* if 1 the node is allocated (used) */
31 }s_allocator_node_t,* allocator_node_t;
33 /* the allocator block type */
34 typedef struct s_allocator_block
36 struct s_allocator* allocator; /* the allocator which contains the block */
37 struct s_allocator_block* next; /* the next block */
38 }s_allocator_block_t,* allocator_block_t;
40 /* the allocator type */
41 typedef struct s_allocator
43 allocator_block_t head; /* the head of the allocator blocks */
44 unsigned int block_capacity; /* the capacity of the allocator blocks (nodes per block) */
45 int capacity; /* the current capacity of the allocator (nodes per block x block count)*/
46 int type_size; /* size of allocated type */
47 int size; /* current node (object) count */
48 allocator_node_t free; /* pointer to the next free node */
49 allocator_node_t first; /* pointer to the first free node */
50 fn_finalize_t fn_finalize; /* pointer to the function used to destroy the allocated objects */
51 }s_allocator_t,* allocator_t;
54 allocator_new(int block_capacity, int type_size, fn_finalize_t fn_finalize);
57 allocator_free(allocator_t* allocator_ptr);
60 allocator_alloc(allocator_t allocator);
63 allocator_dealloc(allocator_t allocator,void* block);
66 allocator_get_size(allocator_t allocator);
69 allocator_get_capacity(allocator_t allocator);
72 allocator_get_type_size(allocator_t allocator);
75 allocator_get_block_capacity(allocator_t allocator);
78 allocator_clear(allocator_t allocator);
81 allocator_get_capacity_available(allocator_t allocator);
84 allocator_is_empty(allocator_t allocator);
87 allocator_is_full(allocator_t allocator);
94 #endif /* !__allocator_H */