This is API for memory pool.
More...
Go to the source code of this file.
This is API for memory pool.
Definition in file memorypool.h.
◆ FOR_ALL_USEDMEM
◆ MemoryPool
MemoryPool class definition, to use API.
Definition at line 12 of file memorypool.h.
◆ mpool_create()
MemoryPool mpool_create |
( |
size_t |
max_size, |
|
|
size_t |
max_cnt, |
|
|
int |
is_multithread, |
|
|
void(*)(void *this, void *constructor_parameter) |
constructor, |
|
|
void * |
constructor_parameter |
|
) |
| |
create MemoryPool class
- Parameters
-
[in] | max_size | max of allocated memory size, to allocate fast, this value will update 2^n in library. |
[in] | max_cnt | number of allocated memory |
[in] | is_multithread | threadsafe flag. If you want to use it on multi thread, please set 1. |
[in] | constructor | if you want to initialize memory first. |
[in] | constructor_parameter | constructor parameter if you want to initialize memory first. |
- Return values
-
!=NULL | this class handle |
NULL | error |
◆ mpool_delete()
void mpool_delete |
( |
MemoryPool |
this, |
|
|
void(*)(void *) |
destructor |
|
) |
| |
free MemoryPool class
- Parameters
-
[in] | this | MemoryPool instance returned at mpool_malloc_new, |
[in] | destructor | if you want to finialize memory |
- Returns
- none
Definition at line 223 of file memorypool.c.
◆ mpool_get()
get memory from pool
- Parameters
-
[in] | this | MemoryPool instance returned at mpool_malloc_new, |
- Return values
-
!=NULL | allocated pointer |
NULL | max_size of allocated memory |
- Note
- If already get all allocated pointer, return NULL
Definition at line 236 of file memorypool.c.
◆ mpool_get_next_usedmem()
void* mpool_get_next_usedmem |
( |
MemoryPool |
this, |
|
|
void * |
ptr |
|
) |
| |
get used memory
- Parameters
-
[in] | this | MemoryPool instance return, |
[in] | ptr | used pointer |
- Return values
-
!=NULL | get next |
NULL | this pointer is end |
Definition at line 245 of file memorypool.c.
◆ mpool_get_usedcnt()
get used cnt
- Parameters
-
[in] | this | MemoryPool instance return, |
- Returns
- used count
Definition at line 257 of file memorypool.c.
◆ mpool_release()
void mpool_release |
( |
MemoryPool |
this, |
|
|
void * |
ptr |
|
) |
| |
release memory to pool
- Parameters
-
[in] | this | MemoryPool instance returned at mpool_malloc_new, |
[in] | ptr | allocated pointer which get from mpool_malloc |
- Returns
- none
- Note
- not initialize memory
Definition at line 266 of file memorypool.c.