design_pattern_for_c  V 1.00
memorypool.h File Reference

This is API for memory pool. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FOR_ALL_USEDMEM(this, ptr)   for(ptr=mpool_get_next_usedmem(this, NULL); ptr!=NULL; ptr = mpool_get_next_usedmem(this, ptr ))
 define for used loop More...
 

Typedefs

typedef struct memorypool_tMemoryPool
 MemoryPool class definition, to use API. More...
 

Functions

MemoryPool mpool_create (size_t max_size, size_t max_cnt, int is_multithread, void(*constructor)(void *this, void *constructor_parameter), void *constructor_parameter)
 create MemoryPool class More...
 
void mpool_delete (MemoryPool this, void(*destructor)(void *))
 free MemoryPool class More...
 
void * mpool_get (MemoryPool this)
 get memory from pool More...
 
void * mpool_get_next_usedmem (MemoryPool this, void *ptr)
 get used memory More...
 
size_t mpool_get_usedcnt (MemoryPool this)
 get used cnt More...
 
void mpool_release (MemoryPool this, void *ptr)
 release memory to pool More...
 

Detailed Description

This is API for memory pool.

Definition in file memorypool.h.

Macro Definition Documentation

◆ FOR_ALL_USEDMEM

#define FOR_ALL_USEDMEM (   this,
  ptr 
)    for(ptr=mpool_get_next_usedmem(this, NULL); ptr!=NULL; ptr = mpool_get_next_usedmem(this, ptr ))

define for used loop

Definition at line 55 of file memorypool.h.

Typedef Documentation

◆ MemoryPool

typedef struct memorypool_t* MemoryPool

MemoryPool class definition, to use API.

Definition at line 12 of file memorypool.h.

Function Documentation

◆ 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_sizemax of allocated memory size, to allocate fast, this value will update 2^n in library.
[in]max_cntnumber of allocated memory
[in]is_multithreadthreadsafe flag. If you want to use it on multi thread, please set 1.
[in]constructorif you want to initialize memory first.
[in]constructor_parameterconstructor parameter if you want to initialize memory first.
Return values
!=NULLthis class handle
NULLerror

◆ mpool_delete()

void mpool_delete ( MemoryPool  this,
void(*)(void *)  destructor 
)

free MemoryPool class

Parameters
[in]thisMemoryPool instance returned at mpool_malloc_new,
[in]destructorif you want to finialize memory
Returns
none

Definition at line 223 of file memorypool.c.

◆ mpool_get()

void* mpool_get ( MemoryPool  this)

get memory from pool

Parameters
[in]thisMemoryPool instance returned at mpool_malloc_new,
Return values
!=NULLallocated pointer
NULLmax_size of allocated memory
Note
If already get all allocated pointer, return NULL

Definition at line 236 of file memorypool.c.

Here is the call graph for this function:

◆ mpool_get_next_usedmem()

void* mpool_get_next_usedmem ( MemoryPool  this,
void *  ptr 
)

get used memory

Parameters
[in]thisMemoryPool instance return,
[in]ptrused pointer
Return values
!=NULLget next
NULLthis pointer is end

Definition at line 245 of file memorypool.c.

Here is the call graph for this function:

◆ mpool_get_usedcnt()

size_t mpool_get_usedcnt ( MemoryPool  this)

get used cnt

Parameters
[in]thisMemoryPool 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]thisMemoryPool instance returned at mpool_malloc_new,
[in]ptrallocated pointer which get from mpool_malloc
Returns
none
Note
not initialize memory

Definition at line 266 of file memorypool.c.

Here is the call graph for this function: