このページを編集する際は,編集に関する方針に従ってください.
概要
* allocate memory from a memory pool
引数
* @param p the pool to use * @param size how much memory to allocate * @return pointer to the allocated memory
実装
- メモリプールpool参照
void *pmalloc(pool p, int size) { void *block;
if(p == NULL) { fprintf(stderr,"Memory Leak! [pmalloc received NULL pool, unable to track allocation, exiting]\n"); abort(); }
/* if there is no heap for this pool or it's a big request, just raw, I like how we clean this :) */ if(p->heap == NULL || size > (p->heap->size / 2)) { block = _retried__malloc(size); p->size += size; _pool_cleanup_append(p, _pool_free(p, _pool__free, block)); return block; }
/* we have to preserve boundaries, long story :) */ if(size >= 4) while(p->heap->used&7) p->heap->used++;
/* if we don't fit in the old heap, replace it */ if(size > (p->heap->size - p->heap->used)) p->heap = _pool_heap(p, p->heap->size);
/* the current heap has room */ block = (char *)p->heap->block + p->heap->used; p->heap->used += size; return block; }
呼出元
Jabberd14-1.6.0/jabberd/lib/pool.c/pmalloco
#related: relatedプラグインは廃止されました。