概要


メジャーヒープ用にメモリをアロケートする。

引数

  • request: 領域の大きさ(バイト単位)。

戻り値


チャンクのアドレス。

実装



/* Allocate a block of the requested size, to be passed to
   [caml_add_to_heap] later.
   [request] must be a multiple of [Page_size].
   [caml_alloc_for_heap] returns NULL if the request cannot be satisfied.
   The returned pointer is a hp, but the header must be initialized by
   the caller.
*/

後でocaml-3.11.0/caml_add_to_heapに渡すため、要求された大きさのブロックをアロケートする。requestはPage_sizeの倍数でなければならない。要求が満たされなかった場合、caml_alloc_for_heapはNULLを返す。返すポインタはhpであるが、ヘッダは呼び出し側が初期化しなければならない。

char *caml_alloc_for_heap (asize_t request)
{
  char *mem;
  void *block;
                                              Assert (request % Page_size == 0);

  mem = caml_aligned_malloc (request + sizeof (heap_chunk_head),
                             sizeof (heap_chunk_head), &block);

チャンクとヘッダをアロケートする。

  if (mem == NULL) return NULL;
  mem += sizeof (heap_chunk_head);

変数memの値が、チャンクへのポインタとなる。

  Chunk_size (mem) = request;

  Chunk_block (mem) = block;

  return mem;
}
タグ

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

管理人/副管理人のみ編集できます