Memory Management
[RT-Thread Kernel API]


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)

Detailed Description

RT-Thread operating system supports two types memory 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

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.

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

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.

Parameters:
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.

Parameters:
hook the hook function

void * rt_malloc ( rt_size_t  size  ) 

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.

void * rt_mp_alloc ( rt_mp_t  mp,
rt_int32_t  time 
)

This function will allocate a block from memory pool

Parameters:
mp the memory pool object
time the waiting time
Returns:
the allocated memory block

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.

Parameters:
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.

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

rt_err_t rt_mp_delete ( rt_mp_t  mp  ) 

This function will delete a memory pool and release the object memory.

Parameters:
mp the memory pool object
Returns:
the operation status, RT_EOK on OK; -RT_ERROR on error

void rt_mp_free ( void *  block  ) 

This function will release a memory block

Parameters:
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.

Parameters:
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.

Parameters:
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
Returns:
the operation status, RT_EOK on OK; RT_ERROR on error

void * rt_realloc ( void *  rmem,
rt_size_t  newsize 
)

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


Generated on Thu Oct 9 07:19:09 2008 for RT-Thread Kernel by  doxygen 1.5.7