Jabberd14-1.6.0/jabberd/lib/pool.c

Last-modified: 2007-03-07 (水) 13:39:18

このページを編集する際は,編集に関する方針に従ってください.

概要

/**
 * @file pool.c
 * @brief Handling of memory pools
 *
 * Jabberd handles its memory allocations in pools. You create a pool, can
 * allocate memory from it and all allocations will be freed if you free
 * the pool. Therefore you don't have to care that each malloc is freed,
 * you only have to take care that the pool is freed.
 *
 * The normal call-flow for pools is:
 *
 * pool p = pool_new();
 * struct mystruct *allocation1 = pmalloc(sizeof(struct mystruct));
 * struct myotherstruct *allocation2 = pmalloc(sizeof(struct myotherstruct));
 * ...
 * pool_free(p);
 */

超意訳

メモリプールを生成すれば、プールからメモリが確保できるし、
プールを開放すれば、確保したすべてのメモリを開放できる。
したがって、個々のmallocがfreeされているかに気を使う必要は無く、
ただ、プールがfreeされているかに気をつければよい。

関数・マクロ

pool _pool_new_heap(int size, char *zone, int line)
void *pmalloc(pool p, int size)

構造体

struct pool_struct

実装

pool->heap /* 現在のheap */
pool->cleanup->heap /* 使い切ったheapたち */
         |
       next--->heap
         |
       next--->heap
         .
         .
         .
  • pfree->fには二種類の関数が入る。
    • ひとつはpheapを開放する関数
    • ひとつはpheapを介さずに確保した領域を開放する関数(普通のfree)
pfree->f /* pool_cleaner */

呼出元

#related: relatedプラグインは廃止されました。