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