---------------------------------------------
-- 时间:2018-11-14
-- 创建人:Ruo_Xiao
-- 邮箱:[email protected]
---------------------------------------------
void OSMemFree(void *pMem)
{
tOSMem_t *ptOSMemTemp = OS_NULL;
//待释放的地址为空则返回
if (pMem == OS_NULL)
{
return;
}
//待释放的地址不在堆中则返回
if ((uOS8_t *)pMem < (uOS8_t *)gpOSMemBegin || (uOS8_t *)pMem >= (uOS8_t *)gpOSMemEnd)
{
return;
}
// protect the heap from concurrent access
OSIntLock();
//得到该内存块对应的信息块(tOSMem_t)
ptOSMemTemp = (tOSMem_t *)(void *)((uOS8_t *)pMem - SIZEOF_OSMEM_ALIGNED);
//该信息块为1,即:正在使用,才能释放该内存
if( ptOSMemTemp->Used==1 )
{
//释放!
ptOSMemTemp->Used = 0;
//若该已经释放的内存块低于gpOSMemLFree,则更新Free指针
if (ptOSMemTemp < gpOSMemLFree)
{
gpOSMemLFree = ptOSMemTemp;
}
//释放完内存,为了避免内存碎片,要进行内存块整理。
OSMemCombine(ptOSMemTemp);
}
OSIntUnlock();
return;
}
(SAW:Game Over!)