]> gitweb.factorcode.org Git - factor.git/blob - vm/allot.hpp
VM: no need for a nursery_space class, it's just a bump_allocator
[factor.git] / vm / allot.hpp
1 namespace factor {
2
3 /*
4  * It is up to the caller to fill in the object's fields in a meaningful
5  * fashion!
6  */
7 /* Allocates memory */
8 inline object* factor_vm::allot_object(cell type, cell size) {
9   FACTOR_ASSERT(!current_gc);
10
11   bump_allocator *nursery = data->nursery;
12   /* If the object is smaller than the nursery, allocate it in the nursery,
13      after a GC if needed */
14   if (nursery->size > size) {
15     /* If there is insufficient room, collect the nursery */
16     if (nursery->here + size > nursery->end)
17       primitive_minor_gc();
18
19     object* obj = nursery->allot(size);
20
21     obj->initialize(type);
22     return obj;
23   } /* If the object is bigger than the nursery, allocate it in
24        tenured space */
25   else
26     return allot_large_object(type, size);
27 }
28
29 }