]> gitweb.factorcode.org Git - factor.git/blob - vm/bump_allocator.hpp
webapps: better style
[factor.git] / vm / bump_allocator.hpp
1 namespace factor {
2
3 struct bump_allocator {
4   // offset of 'here' and 'end' is hardcoded in compiler backends
5   cell here;
6   cell start;
7   cell end;
8   cell size;
9
10   bump_allocator(cell size, cell start)
11       : here(start), start(start), end(start + size), size(size) {}
12
13   bool contains_p(object* obj) {
14     return (cell)obj >= start && (cell)obj < end;
15   }
16
17   object* allot(cell size) {
18     cell h = here;
19     here = h + align(size, data_alignment);
20     return (object*)h;
21   }
22
23   cell occupied_space() { return here - start; }
24
25   cell free_space() { return end - here; }
26
27   void flush() {
28     here = start;
29 #ifdef FACTOR_DEBUG
30     // In case of bugs, there may be bogus references pointing to the
31     // memory space after the gc has run. Filling it with a pattern
32     // makes accesses to such shadow data fail hard.
33     memset_cell((void*)start, 0xbaadbaad, size);
34 #endif
35   }
36 };
37
38 }