diff --git a/common/include/villas/memory.hpp b/common/include/villas/memory.hpp index 7ce425e70..b4c3497a0 100644 --- a/common/include/villas/memory.hpp +++ b/common/include/villas/memory.hpp @@ -76,6 +76,12 @@ public: memoryBlock(std::move(mem)) { } + // Take ownership of the MemoryBlock + MemoryAccessor(std::shared_ptr mem) : + translation(MemoryManager::get().getTranslationFromProcess(mem->getAddrSpaceId())), + memoryBlock(std::move(mem)) + { } + // Just act as an accessor, do not take ownership of MemoryBlock MemoryAccessor(const MemoryBlock &mem) : translation(MemoryManager::get().getTranslationFromProcess(mem.getAddrSpaceId())) @@ -106,10 +112,10 @@ public: return reinterpret_cast(translation.getLocalAddr(0)); } - const MemoryBlock& + const std::shared_ptr getMemoryBlock() const { - if (not memoryBlock) throw std::bad_alloc(); else return *memoryBlock; + if (not memoryBlock) throw std::bad_alloc(); else return memoryBlock; } private: @@ -117,7 +123,7 @@ private: MemoryTranslation translation; // Take the unique pointer in case user wants this class to have ownership - std::unique_ptr memoryBlock; + std::shared_ptr memoryBlock; }; /**