1 #pragma once 2 3 #include <map> 4 #include <mutex> 5 #include <sstream> 6 7 #include "region.h" 8 #include "types.h" 9 10 11 12 /* Memory map entry. */ 13 14 typedef std::map<offset_t, Region *> _MemoryMap; 15 typedef std::pair<offset_t, Region *> _MemoryMapEntry; 16 17 18 19 /* Memory organised as a collection of regions. */ 20 21 class MemoryMap 22 { 23 protected: 24 std::mutex _lock; 25 _MemoryMap _regions; 26 27 public: 28 /* Region maintenance. */ 29 30 void insert(Region *region); 31 32 void remove(Region *region); 33 34 /* Debugging methods. */ 35 36 void show(std::ostringstream &buffer); 37 }; 38 39 40 41 /* An allocator abstraction. */ 42 43 class Allocator : public MemoryMap 44 { 45 public: 46 Region *region(offset_t size); 47 48 void release(Region *region); 49 }; 50 51 // vim: tabstop=4 expandtab shiftwidth=4