|
发表于 2007-3-13 13:31:02
|
显示全部楼层
#define RT_Memory_Pool_Size 100*1024
//开内存池
static NU_MEMORY_POOL RTPool;
__align(4) const unsigned char Memorypool[RT_Memory_Pool_Size];
//在内存池内动态分配内存
STATUS RT_Create_Memory_Pool()
{
STATUS status;
status = NU_Create_Memory_Pool(&RTPool,
"any name",
(VOID *)Memorypool,
RT_Memory_Pool_Size,
30,
NU_PRIORITY);
return status;
}
//实现以下三个函数
//_malloc(nob)
void* _malloc( unsigned int size )
{
STATUS status;
void *memory_ptr;
status = NU_Allocate_Memory(&RTPool,
&memory_ptr,
size,
NU_SUSPEND);
switch(status)
{
case NU_SUCCESS:
return memory_ptr;
case NU_INVALID_POOL:
case NU_NO_MEMORY:
case NU_TIMEOUT:
break;
}
}
// _free(frp)
void _free (void* buff_pt)
{
STATUS status;
status= NU_Deallocate_Memory(buff_pt);
#if 0
switch(status)
{
case NU_SUCCESS:
return 1;
case NU_INVALID_POINTER:
default:
return 0;
}
#endif
} |
|