]> gitweb.factorcode.org Git - factor.git/blob - vm/bump_allocator.hpp
vm: split off free_list_allocator from heap class, rename zone to bump_allocator
[factor.git] / vm / bump_allocator.hpp
1 namespace factor
2 {
3
4 struct bump_allocator {
5         /* offset of 'here' and 'end' is hardcoded in compiler backends */
6         cell here;
7         cell start;
8         cell end;
9         cell size;
10
11         bump_allocator(cell size_, cell start_) :
12                 here(0), start(start_), end(start_ + size_), size(size_) {}
13
14         inline bool contains_p(object *pointer)
15         {
16                 return ((cell)pointer - start) < size;
17         }
18
19         inline object *allot(cell size)
20         {
21                 cell h = here;
22                 here = h + align(size,data_alignment);
23                 return (object *)h;
24         }
25
26         cell next_allocated_block_after(cell scan)
27         {
28                 cell size = ((object *)scan)->size();
29                 if(scan + size < here)
30                         return scan + size;
31                 else
32                         return 0;
33         }
34 };
35
36 }