1 #include "memory.h" 2 3 #include <stdlib.h> 4 5 6 /* Initialise the memory pool with an optional 'limit' in pages. */ 7 8 Memory::Memory(offset_t region_size) 9 : _region_size(region_size) 10 { 11 } 12 13 /* Allocate a block of the given 'size'. */ 14 15 Region *Memory::allocate(offset_t size) 16 { 17 /* Attempt to allocate aligned memory. */ 18 19 void *current; 20 21 /* Make the size appropriate for the invocation. */ 22 23 size = round_multiple(size, PAGE_SIZE); 24 25 if (posix_memalign(¤t, size, size)) 26 return NULL; 27 28 return new Region((offset_t) current, (offset_t) current + size); 29 } 30 31 // vim: tabstop=4 expandtab shiftwidth=4