C??????????????
???????????? ???????[ 2012/9/29 15:31:32 ] ????????
????????????????
???????????????????????????????????????????struct pool_struct???????????????????????顣
void pool_free(pool_t p)
{
struct pfree *cur?? *stub;
if(p == NULL) return;
cur = p->cleanup;
while(cur != NULL)
{
(*cur->f)(cur->arg); // ????????malloc??????????struct pheap??????????檔????????_pool_heap_free????
stub = cur->next;
free(cur); // ???pfree????
cur = stub;
}
free(p); //???pool_struct??????????檔
}
???????????????????
????????????????????δ??????з????????б???????棬?????????????????з???size??С????棬?????????????????
void *pool_malloc(pool_t p?? int size)
{
void *block;
if(p == NULL)
{
fprintf(stderr??"Memory Leak! [pmalloc received NULL pool?? unable to track allocation?? exiting]
");
abort();
}
if(p->heap == NULL || size > (p->heap->size / 2))
{
while((block = malloc(size)) == NULL) sleep(1);
p->size += size;
_pool_cleanup_append(p?? _pool_free(p?? _pool__free?? block));
return block;
}
if(size >= 4)
while(p->heap->used&7) p->heap->used++; // ??????????????????????????????8???????????????????8???????
if(size > (p->heap->size - p->heap->used))
p->heap = _pool_heap(p?? p->heap->size);
block = (char *)p->heap->block + p->heap->used;
p->heap->used += size; //?????ò?????????????????????????????????
return block;
}
???????????????У??????????????????????£?
????1????????????????????????????????????????????????????????malloc??????????檔???????????????????С?
????2??????????水??????????ж????????????????????????????????????á?
????3??????????μ?????????????С?????????size???????????????μ????飬???????????
????4?????????????????p->heap->used????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11