Functions | |
| rt_err_t | rt_mp_init (struct rt_mempool *mp, const char *name, void *start, rt_size_t size, rt_size_t block_size) |
| rt_mp_t | rt_mp_create (const char *name, rt_size_t block_count, rt_size_t block_size) |
| rt_err_t | rt_mp_delete (rt_mp_t mp) |
| void * | rt_mp_alloc (rt_mp_t mp, rt_int32_t time) |
| void | rt_mp_free (void *block) |
| void | rt_mp_alloc_sethook (void(*hook)(void *block)) |
| void | rt_mp_free_sethook (void(*hook)(void *block)) |
| void * | rt_malloc (rt_size_t nbytes) |
| void | rt_free (void *ptr) |
| void * | rt_realloc (void *ptr, rt_size_t nbytes) |
| void | rt_free_sethook (void(*hook)(void *ptr)) |
| void * | rt_calloc (rt_size_t count, rt_size_t size) |
The time to allocate a memory block from the memory pool is determinant. When the memory pool is empty, the allocated thread can be blocked (or immediately return, or waiting for sometime to return, which are determined by a timeout parameter). When other thread releases memory blocks to this memory pool, the blocked thread is wake up.
There are two methods in dynamic memory heap management, one is used for small memory, such as less than 1MB. Another is a SLAB like memory management, which is suitable for large memory system. All of them has no real-time character.
| void* rt_calloc | ( | rt_size_t | count, | |
| rt_size_t | size | |||
| ) |
This function will contiguously allocate enough space for count objects that are size bytes of memory each and returns a pointer to the allocated memory.
The allocated memory is filled with bytes of value zero.
| count | number of objects to allocate | |
| size | size of the objects to allocate |
| void rt_free | ( | void * | rmem | ) |
This function will release the previously allocated memory block by rt_malloc. The released memory block is taken back to system heap.
| rmem | the address of memory which will be released |
| void rt_free_sethook | ( | void(*)(void *ptr) | hook | ) |
This function will set a hook function, which will be invoked when a memory block is released to heap memory.
| hook | the hook function |
| void * rt_malloc | ( | rt_size_t | size | ) |
Allocate a block of memory with a minimum of 'size' bytes.
| size | is the minimum size of the requested block in bytes. |
| void * rt_mp_alloc | ( | rt_mp_t | mp, | |
| rt_int32_t | time | |||
| ) |
This function will allocate a block from memory pool
| mp | the memory pool object | |
| time | the waiting time |
| void rt_mp_alloc_sethook | ( | void(*)(void *block) | hook | ) |
This function will set a hook function, which will be invoked when a memory block is allocated from memory pool.
| hook | the hook function |
| rt_mp_t rt_mp_create | ( | const char * | name, | |
| rt_size_t | block_count, | |||
| rt_size_t | block_size | |||
| ) |
This function will create a mempool object and allocate the memory pool from heap.
| name | the name of memory pool | |
| block_count | the count of blocks in memory pool | |
| block_size | the size for each block |
| rt_err_t rt_mp_delete | ( | rt_mp_t | mp | ) |
This function will delete a memory pool and release the object memory.
| mp | the memory pool object |
| void rt_mp_free | ( | void * | block | ) |
This function will release a memory block
| block | the address of memory block to be released |
| void rt_mp_free_sethook | ( | void(*)(void *block) | hook | ) |
This function will set a hook function, which will be invoked when a memory block is released to memory pool.
| hook | the hook function |
| rt_err_t rt_mp_init | ( | struct rt_mempool * | mp, | |
| const char * | name, | |||
| void * | start, | |||
| rt_size_t | size, | |||
| rt_size_t | block_size | |||
| ) |
This function will initialize a mempool object, normally which is used for static object.
| mp | the mempool object | |
| name | the name of memory pool | |
| start | the star address of memory pool | |
| size | the total size of memory pool | |
| block_size | the size for each block |
| void * rt_realloc | ( | void * | rmem, | |
| rt_size_t | newsize | |||
| ) |
This function will change the previously allocated memory block.
| rmem | pointer to memory allocated by rt_malloc | |
| newsize | the required new size |
1.5.7