Data Structures |
struct | rt_mempool |
Functions |
void * | rt_malloc (rt_size_t size) |
void * | rt_realloc (void *rmem, rt_size_t newsize) |
void * | rt_calloc (rt_size_t count, rt_size_t size) |
void | rt_free (void *rmem) |
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_err_t | rt_mp_detach (struct rt_mempool *mp) |
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)(struct rt_mempool *mp, void *block)) |
void | rt_mp_free_sethook (void(*hook)(struct rt_mempool *mp, void *block)) |
void | rt_system_heap_init (void *begin_addr, void *end_addr) |
void | rt_malloc_sethook (void(*hook)(void *ptr, rt_uint32_t size)) |
void | rt_free_sethook (void(*hook)(void *ptr)) |
Detailed Description
RT-Thread operating system supports two types memory management:
- Static memory pool management
- Dynamic memory heap management.
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.
Function Documentation
Allocate a block of memory with a minimum of 'size' bytes.
- Parameters:
-
size | is the minimum size of the requested block in bytes. |
- Returns:
- pointer to allocated memory or NULL if no free memory was found.
This function will change the previously allocated memory block.
- Parameters:
-
rmem | pointer to memory allocated by rt_malloc |
newsize | the required new size |
- Returns:
- the changed memory block address
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.
- Parameters:
-
count | number of objects to allocate |
size | size of the objects to allocate |
- Returns:
- pointer to allocated memory / NULL pointer if there is an error
This function will release the previously allocated memory block by rt_malloc. The released memory block is taken back to system heap.
- Parameters:
-
rmem | the address of memory which will be released |
This function will initialize a memory pool object, normally which is used for static object.
- Parameters:
-
mp | the memory pool 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 |
- Returns:
- RT_EOK
This function will detach a memory pool from system object management.
- Parameters:
-
- Returns:
- RT_EOK
This function will create a mempool object and allocate the memory pool from heap.
- Parameters:
-
name | the name of memory pool |
block_count | the count of blocks in memory pool |
block_size | the size for each block |
- Returns:
- the created mempool object
This function will delete a memory pool and release the object memory.
- Parameters:
-
- Returns:
- RT_EOK
This function will allocate a block from memory pool
- Parameters:
-
mp | the memory pool object |
time | the waiting time |
- Returns:
- the allocated memory block or RT_NULL on allocated failed
This function will release a memory block
- Parameters:
-
block | the address of memory block to be released |
This function will set a hook function, which will be invoked when a memory block is allocated from memory pool.
- Parameters:
-
This function will set a hook function, which will be invoked when a memory block is released to memory pool.
- Parameters:
-
This function will init system heap
- Parameters:
-
begin_addr | the beginning address of system page |
end_addr | the end address of system page |
This function will initialize system heap memory.
- Parameters:
-
begin_addr | the beginning address of system heap memory. |
end_addr | the end address of system heap memory. |
This function will set a hook function, which will be invoked when a memory block is allocated from heap memory.
- Parameters:
-
This function will set a hook function, which will be invoked when a memory block is released to heap memory.
- Parameters:
-