From cb233fbf4cffb60790692bb2a358d8937ef1cd01 Mon Sep 17 00:00:00 2001 From: Emiel Por Date: Sun, 22 Dec 2024 12:22:17 -0800 Subject: [PATCH] Add local memory for testing purposes. --- catkit_core/CMakeLists.txt | 1 + catkit_core/LocalMemory.cpp | 16 ++++++++++++++++ catkit_core/LocalMemory.h | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 catkit_core/LocalMemory.cpp create mode 100644 catkit_core/LocalMemory.h diff --git a/catkit_core/CMakeLists.txt b/catkit_core/CMakeLists.txt index 7afde58a..2264c90d 100644 --- a/catkit_core/CMakeLists.txt +++ b/catkit_core/CMakeLists.txt @@ -37,6 +37,7 @@ add_library(catkit_core STATIC FreeListAllocator.cpp MessageBroker.cpp UuidGenerator.cpp + LocalMemory.cpp proto/core.pb.cc proto/logging.pb.cc proto/testbed.pb.cc diff --git a/catkit_core/LocalMemory.cpp b/catkit_core/LocalMemory.cpp new file mode 100644 index 00000000..57120fc0 --- /dev/null +++ b/catkit_core/LocalMemory.cpp @@ -0,0 +1,16 @@ +#include "LocalMemory.h" + +LocalMemory::LocalMemory(std::size_t num_bytes) + : m_Memory(new char[num_bytes]) +{ +} + +LocalMemory::~LocalMemory() +{ + delete[] m_Memory; +} + +void *LocalMemory::GetAddress(std::size_t offset) +{ + return m_Memory + offset; +} diff --git a/catkit_core/LocalMemory.h b/catkit_core/LocalMemory.h new file mode 100644 index 00000000..d237b9db --- /dev/null +++ b/catkit_core/LocalMemory.h @@ -0,0 +1,18 @@ +#ifndef LOCAL_MEMORY_H +#define LOCAL_MEMORY_H + +#include "Memory.h" + +class LocalMemory : public Memory +{ +public: + LocalMemory(std::size_t num_bytes); + virtual ~LocalMemory(); + + virtual void *GetAddress(std::size_t offset = 0); + +private: + char *m_Memory; +}; + +#endif // LOCAL_MEMORY_H