最終更新:ID:55w90ThOAA 2009年04月17日(金) 22:15:58履歴
/* Take a chunk of memory as argument, which must be the result of a call to [caml_alloc_for_heap], and insert it into the heap chaining. The contents of the chunk must be a sequence of valid blocks and fragments: no space between blocks and no trailing garbage. If some blocks are blue, they must be added to the free list by the caller. All other blocks must have the color [caml_allocation_color(m)]. The caller must update [caml_allocated_words] if applicable. Return value: 0 if no error; -1 in case of error. */
引数としてメモリのチャンクを受け取り、これはocaml-3.11.0/caml_alloc_for_heapの呼び出しの結果でなければならず、ヒープのリストにこれを追加する。このチャンクの内容は、正当なブロックと断片のシーケンスでなければならない: ブロック間に余白はなく、ゴミが続いたりしない。青色のブロックがあれば、呼び出し側がこれらをフリーリストに追加しなければならない。他のすべてのブロックは、色ocaml-3.11.0/caml_allocation_colorの色を持たなければならない。適用可能ならば、呼び出し側はocaml-3.11.0/caml_allocated_wordsを更新しなければならない。エラーがない場合、0を返し、エラーがある場合は-1を返す。
int caml_add_to_heap (char *m) { Assert (Chunk_size (m) % Page_size == 0);
#ifdef DEBUG /* Should check the contents of the block. */ #endif /* debug */ caml_gc_message (0x04, "Growing heap to %luk bytes\n", (caml_stat_heap_size + Chunk_size (m)) / 1024); /* Register block in page table */
ブロックをページテーブルに登録する。
if (caml_page_table_add(In_heap, m, m + Chunk_size(m)) != 0)
チャンク内のすべてのページに、In_heapフラグを立てる。
return -1; /* Chain this heap chunk. */
このヒープのチャンクをつなぐ。
{ char **last = &caml_heap_start;
char *cur = *last; while (cur != NULL && cur < m){ last = &(Chunk_next (cur));
cur = *last; } Chunk_next (m) = cur; *last = m; ++ caml_stat_heap_chunks;
} caml_stat_heap_size += Chunk_size (m);
if (caml_stat_heap_size > caml_stat_top_heap_size){
caml_stat_top_heap_size = caml_stat_heap_size; } return 0; }
タグ
このページへのコメント
uZ3OIY wow, awesome blog post.Much thanks again. Really Great.