Make buddy more dynamic

This commit is contained in:
Baptiste Wicht 2014-02-07 20:56:05 +01:00
parent 8b52ef4713
commit f0006809b4
2 changed files with 12 additions and 4 deletions

View File

@ -15,16 +15,22 @@ inline constexpr T pow(T const& x, size_t n){
return n > 0 ? x * pow(x, n - 1) : 1;
}
template<size_t Levels, size_t First, size_t Last, size_t Unit>
template<size_t Levels, size_t Unit>
struct buddy_allocator {
static constexpr const size_t levels = Levels;
static constexpr const size_t max_block = pow(2, levels - 1);
static constexpr const size_t first_address = First;
static constexpr const size_t last_address = Last;
std::array<static_bitmap, levels> bitmaps;
size_t first_address;
size_t last_address;
public:
void set_memory_range(size_t first, size_t last){
first_address = first;
last_address = last;
}
template<size_t I>
void init(size_t words, uint64_t* data){
bitmaps[I].init(words, data);

View File

@ -38,12 +38,14 @@ std::array<uint64_t, array_size(32)> data_bitmap_32;
std::array<uint64_t, array_size(64)> data_bitmap_64;
std::array<uint64_t, array_size(128)> data_bitmap_128;
typedef buddy_allocator<8, first_virtual_address, last_virtual_address, unit> buddy_type;
typedef buddy_allocator<8, unit> buddy_type;
buddy_type allocator;
} //end of anonymous namespace
void virtual_allocator::init(){
allocator.set_memory_range(first_virtual_address, last_virtual_address);
//Give room to the bitmaps
allocator.init<0>(array_size(1), data_bitmap_1.data());
allocator.init<1>(array_size(2), data_bitmap_2.data());