factor/vm/bump_allocator.hpp

28 lines
504 B
C++
Raw Normal View History

namespace factor
{
template<typename Block> struct bump_allocator {
/* offset of 'here' and 'end' is hardcoded in compiler backends */
cell here;
cell start;
cell end;
cell size;
bump_allocator(cell size_, cell start_) :
here(start_), start(start_), end(start_ + size_), size(size_) {}
inline bool contains_p(Block *block)
{
return ((cell)block - start) < size;
}
inline Block *allot(cell size)
{
cell h = here;
2009-10-20 13:45:00 -04:00
here = h + align(size,data_alignment);
return (Block *)h;
}
};
}