* このページを編集する際は,[[編集に関する方針>編集方針]]に従ってください. [#z1b18a3b]
* 概要 [#j7980619]
- [[Jabberd14-1.6.0/jabberd/lib/pool.c]]にて定義
* allocate memory from a memory pool
* 引数 [#p3f21dd6]
* @param p the pool to use
* @param size how much memory to allocate
* @return pointer to the allocated memory
* 実装 [#v0d545ab]
- メモリプール[[pool>Jabberd14-1.6.0/jabberd/lib/jabberdlib.h/struct pool_struct]]参照
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;
}
* 呼出元 [#rfeda7ab]
[[Jabberd14-1.6.0/jabberd/lib/pool.c/pmalloco]]
#related