29 #ifndef POOL_ALLOCATOR_H 30 #define POOL_ALLOCATOR_H 45 POOL_ALLOCATOR_INVALID_ID=-1
54 CHECK_LEN=(1<<CHECK_BITS),
55 CHECK_MASK=CHECK_LEN-1
67 inline void clear() { pos=0; len=0; lock=0; check=0; }
72 typedef int EntryArrayPos;
73 typedef int EntryIndicesPos;
87 unsigned int check_count;
92 inline int entry_end(
const Entry& p_entry)
const {
93 return p_entry.pos+aligned(p_entry.len);
95 inline int aligned(
int p_size)
const {
104 void compact(
int p_up_to=-1);
105 void compact_up(
int p_from=0);
106 bool get_free_entry(EntryArrayPos* p_pos);
107 bool find_hole(EntryArrayPos *p_pos,
int p_for_size);
108 bool find_entry_index(EntryIndicesPos *p_map_pos,Entry *p_entry);
109 Entry* get_entry(ID p_mem);
110 const Entry* get_entry(ID p_mem)
const;
112 void create_pool(
void * p_mem,
int p_size,
int p_max_entries);
120 DEFAULT_MAX_ALLOCS=4096,
123 ID
alloc(
int p_size);
125 Error
resize(ID p_mem,
int p_new_size);
126 int get_size(ID p_mem)
const;
129 int get_used_mem()
const;
132 Error lock(ID p_mem);
134 const void *
get(ID p_mem)
const;
135 void unlock(ID p_mem);
136 bool is_locked(ID p_mem)
const;
138 PoolAllocator(
int p_size,
bool p_needs_locking=
false,
int p_max_entries=DEFAULT_MAX_ALLOCS);
139 PoolAllocator(
void * p_mem,
int p_size,
int p_align = 1,
bool p_needs_locking=
false,
int p_max_entries=DEFAULT_MAX_ALLOCS);
140 PoolAllocator(
int p_align,
int p_size,
bool p_needs_locking=
false,
int p_max_entries=DEFAULT_MAX_ALLOCS);
virtual void mt_unlock() const
Reimplement for custom mt locking.
Definition: pool_allocator.cpp:48
ID alloc(int p_size)
Alloc memory, get an ID on success, POOL_ALOCATOR_INVALID_ID on failure.
Definition: pool_allocator.cpp:192
Error resize(ID p_mem, int p_new_size)
resize a memory chunk
Definition: pool_allocator.cpp:343
void free(ID p_mem)
Free allocated memory.
Definition: pool_allocator.cpp:286
int get_free_peak()
get free memory
Definition: pool_allocator.cpp:580
virtual void mt_lock() const
Reimplement for custom mt locking.
Definition: pool_allocator.cpp:44
int get_free_mem()
get free memory
Definition: pool_allocator.cpp:585
Definition: pool_allocator.h:48