From 4105069f7d0e143efc7d953e348324a9176619a3 Mon Sep 17 00:00:00 2001 From: mou Date: Mon, 3 Apr 2023 04:03:35 +0800 Subject: [PATCH] resolve #18 Add C++ allocator (partial) - Compiled successfully without any errors. - Add allocator implementation in rfaaslib. - Encapsulate the memory registration in rdmalib - Add test demonstrating standard memory allocation. --- rfaas/include/rfaas/rdma_allocator.hpp | 15 +++++++++++++-- rfaas/lib/rdma_allocator.cpp | 25 ------------------------- 2 files changed, 13 insertions(+), 27 deletions(-) delete mode 100644 rfaas/lib/rdma_allocator.cpp diff --git a/rfaas/include/rfaas/rdma_allocator.hpp b/rfaas/include/rfaas/rdma_allocator.hpp index c46029a..3b5946d 100644 --- a/rfaas/include/rfaas/rdma_allocator.hpp +++ b/rfaas/include/rfaas/rdma_allocator.hpp @@ -18,9 +18,20 @@ namespace rfaas { public: inline explicit RdmaAllocator(const executor &executor) noexcept: _executor(executor) {} - inline T *allocate(const std::size_t &, const int &, int = 0); + // inline T *allocate(const std::size_t &, const int &, int = 0); + inline T *allocate(const std::size_t &size, const int &access, int header=0) { + if (size > std::size_t(-1) / sizeof(T)) + throw std::bad_alloc(); - inline void deallocate(T *p, std::size_t n) noexcept; + auto buffer = new rdmalib::Buffer(size, header); + buffer->register_memory(_executor._state.pd(), access); + std::cout << "allocate memory by RdmaAllocator" << std::endl; + return buffer; + } + + inline void deallocate(T *p, std::size_t n) noexcept { + operator delete(p); + } }; } diff --git a/rfaas/lib/rdma_allocator.cpp b/rfaas/lib/rdma_allocator.cpp deleted file mode 100644 index a9d9d6c..0000000 --- a/rfaas/lib/rdma_allocator.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// -// Created by mou on 4/2/23. -// -#include - -#include - -namespace rfaas { - - template - inline T *RdmaAllocator::allocate(const std::size_t &size, const int &access, int header) { - if (size > std::size_t(-1) / sizeof(T)) - throw std::bad_alloc(); - - rdmalib::Buffer buffer(size, header); - buffer.register_memory(_executor._state.pd(), access); - - return buffer; - } - - template - inline void RdmaAllocator::deallocate(T *p, std::size_t n) noexcept { - operator delete(p); - } -} \ No newline at end of file