-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReservedBlock.cc
36 lines (29 loc) · 1.03 KB
/
ReservedBlock.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "ReservedBlock.h"
#include "DeviceHeap.h"
#include "MemoryBlock.h"
MemoryBlock ReservedBlock::GetMemoryBlock() const {
return MemoryBlock{.offset = info_.availableOffset,
.size = info_.availableSize};
}
ReservedBlock::ReservedBlock() : heap_(nullptr) {}
ReservedBlock::ReservedBlock(DeviceHeap* heap, Allocator::MemoryObject* memory,
AllocationInfo info)
: heap_(heap), memory_(memory), info_(info) {}
ReservedBlock::~ReservedBlock() {
if (heap_ != nullptr) {
heap_->Return({.allocationIndex = info_.allocationIndex,
.offset = info_.allocationOffset,
.size = info_.allocationSize});
}
}
ReservedBlock::ReservedBlock(ReservedBlock&& other) noexcept
: heap_(other.heap_), memory_(other.memory_), info_(other.info_) {
other.heap_ = nullptr;
}
ReservedBlock& ReservedBlock::operator=(ReservedBlock&& other) noexcept {
heap_ = other.heap_;
memory_ = other.memory_;
info_ = other.info_;
other.heap_ = nullptr;
return *this;
}