summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/fs_memory_management.h
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2024-01-26 15:55:25 +0100
committerGitHub <noreply@github.com>2024-01-26 15:55:25 +0100
commit55482ab5dce463d5014498b006c18a90d0d004e6 (patch)
treeb343faa9cadc692265efb4b6b88e157c97ef76d2 /src/core/file_sys/fs_memory_management.h
parentMerge pull request #12796 from t895/controller-optimizations (diff)
parentAddress review comments and fix compilation problems (diff)
downloadyuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.gz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.bz2
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.lz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.xz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.zst
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.zip
Diffstat (limited to 'src/core/file_sys/fs_memory_management.h')
-rw-r--r--src/core/file_sys/fs_memory_management.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/core/file_sys/fs_memory_management.h b/src/core/file_sys/fs_memory_management.h
new file mode 100644
index 000000000..f03c6354b
--- /dev/null
+++ b/src/core/file_sys/fs_memory_management.h
@@ -0,0 +1,40 @@
+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <mutex>
+#include "common/alignment.h"
+
+namespace FileSys {
+
+constexpr size_t RequiredAlignment = alignof(u64);
+
+void* AllocateUnsafe(size_t size) {
+ // Allocate
+ void* const ptr = ::operator new(size, std::align_val_t{RequiredAlignment});
+
+ // Check alignment
+ ASSERT(Common::IsAligned(reinterpret_cast<uintptr_t>(ptr), RequiredAlignment));
+
+ // Return allocated pointer
+ return ptr;
+}
+
+void DeallocateUnsafe(void* ptr, size_t size) {
+ // Deallocate the pointer
+ ::operator delete(ptr, std::align_val_t{RequiredAlignment});
+}
+
+void* Allocate(size_t size) {
+ return AllocateUnsafe(size);
+}
+
+void Deallocate(void* ptr, size_t size) {
+ // If the pointer is non-null, deallocate it
+ if (ptr != nullptr) {
+ DeallocateUnsafe(ptr, size);
+ }
+}
+
+} // namespace FileSys