aboutsummaryrefslogtreecommitdiff
path: root/src/common/virtual_buffer.h
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2020-11-17 19:58:41 -0500
committerLioncash <mathew1800@gmail.com>2020-11-17 20:08:20 -0500
commitb9b02276ebd81b0579784c97006ce9d9cc18fb06 (patch)
tree9be666d43f15154ee3df2001ced3972cc31a99d7 /src/common/virtual_buffer.h
parent60b72b1debde587546f6f0b03bcef19c185cb091 (diff)
page_table: Allow page tables to be moved
Makes page tables and virtual buffers able to be moved, but not copied, making the interface more flexible. Previously, with the destructor specified, but no move assignment or constructor specified, they wouldn't be implicitly generated.
Diffstat (limited to 'src/common/virtual_buffer.h')
-rw-r--r--src/common/virtual_buffer.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h
index 125cb42f09..363913d452 100644
--- a/src/common/virtual_buffer.h
+++ b/src/common/virtual_buffer.h
@@ -4,25 +4,38 @@
#pragma once
-#include "common/common_funcs.h"
+#include <utility>
namespace Common {
-void* AllocateMemoryPages(std::size_t size);
-void FreeMemoryPages(void* base, std::size_t size);
+void* AllocateMemoryPages(std::size_t size) noexcept;
+void FreeMemoryPages(void* base, std::size_t size) noexcept;
template <typename T>
-class VirtualBuffer final : NonCopyable {
+class VirtualBuffer final {
public:
constexpr VirtualBuffer() = default;
explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} {
base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size));
}
- ~VirtualBuffer() {
+ ~VirtualBuffer() noexcept {
FreeMemoryPages(base_ptr, alloc_size);
}
+ VirtualBuffer(const VirtualBuffer&) = delete;
+ VirtualBuffer& operator=(const VirtualBuffer&) = delete;
+
+ VirtualBuffer(VirtualBuffer&& other) noexcept
+ : alloc_size{std::exchange(other.alloc_size, 0)}, base_ptr{std::exchange(other.base_ptr),
+ nullptr} {}
+
+ VirtualBuffer& operator=(VirtualBuffer&& other) noexcept {
+ alloc_size = std::exchange(other.alloc_size, 0);
+ base_ptr = std::exchange(other.base_ptr, nullptr);
+ return *this;
+ }
+
void resize(std::size_t count) {
FreeMemoryPages(base_ptr, alloc_size);