| 63 | |
| 64 | // MemoryBlock::Desc describes a MemoryBlock. |
| 65 | struct Desc { |
| 66 | Desc(MemoryBlock::Type t, |
| 67 | size_t i, |
| 68 | size_t s, |
| 69 | size_t ts, |
| 70 | MemoryBlock* l, |
| 71 | MemoryBlock* r); |
| 72 | Desc(); |
| 73 | |
| 74 | // mutator for type |
| 75 | inline void set_type(const MemoryBlock::Type& type) { |
| 76 | this->type = type; |
| 77 | this->UpdateGuards(); |
| 78 | } |
| 79 | |
| 80 | // accessor for type |
| 81 | inline const MemoryBlock::Type& get_type() const { return this->type; } |
| 82 | |
| 83 | // accessor for index |
| 84 | inline const size_t& get_index() const { return this->index; } |
| 85 | |
| 86 | // accessor for size |
| 87 | inline const size_t& get_size() const { return this->size; } |
| 88 | |
| 89 | // accessor for total_size |
| 90 | inline const size_t& get_total_size() const { return this->total_size; } |
| 91 | |
| 92 | // Updates guard_begin and guard_end by hashes of the Metadata object. |
| 93 | void UpdateGuards(); |
| 94 | |
| 95 | // Checks that guard_begin and guard_end are hashes of the Metadata object. |
| 96 | bool CheckGuards() const; |
| 97 | |
| 98 | // TODO(gangliao): compress this |
| 99 | size_t guard_begin = 0; |
| 100 | MemoryBlock::Type type = MemoryBlock::INVALID_CHUNK; |
| 101 | size_t index = 0; |
| 102 | size_t size = 0; |
| 103 | size_t total_size = 0; |
| 104 | MemoryBlock* left_buddy = nullptr; |
| 105 | MemoryBlock* right_buddy = nullptr; |
| 106 | size_t guard_end = 0; |
| 107 | }; |
| 108 | }; |
| 109 | |
| 110 | // A cache for accessing memory block meta-data that may be expensive |