| @@ -235,15 +235,15 @@ std::ostream &operator<<(std::ostream &os, const ArenaImpl &s) { | |||||
| Status Arena::Init() { | Status Arena::Init() { | ||||
| try { | try { | ||||
| int64_t sz = size_in_MB_ * 1048576L; | int64_t sz = size_in_MB_ * 1048576L; | ||||
| RETURN_IF_NOT_OK(mem_.allocate(sz)); | |||||
| impl_ = std::make_unique<ArenaImpl>(mem_.GetMutablePointer(), sz); | |||||
| RETURN_IF_NOT_OK(DeMalloc(sz, &ptr_, false)); | |||||
| impl_ = std::make_unique<ArenaImpl>(ptr_, sz); | |||||
| } catch (std::bad_alloc &e) { | } catch (std::bad_alloc &e) { | ||||
| return Status(StatusCode::kOutOfMemory); | return Status(StatusCode::kOutOfMemory); | ||||
| } | } | ||||
| return Status::OK(); | return Status::OK(); | ||||
| } | } | ||||
| Arena::Arena(size_t val_in_MB) : size_in_MB_(val_in_MB) {} | |||||
| Arena::Arena(size_t val_in_MB) : ptr_(nullptr), size_in_MB_(val_in_MB) {} | |||||
| Status Arena::CreateArena(std::shared_ptr<Arena> *p_ba, size_t val_in_MB) { | Status Arena::CreateArena(std::shared_ptr<Arena> *p_ba, size_t val_in_MB) { | ||||
| RETURN_UNEXPECTED_IF_NULL(p_ba); | RETURN_UNEXPECTED_IF_NULL(p_ba); | ||||
| @@ -104,7 +104,12 @@ class Arena : public MemoryPool { | |||||
| // Disable copy and assignment constructor | // Disable copy and assignment constructor | ||||
| Arena(const Arena &) = delete; | Arena(const Arena &) = delete; | ||||
| Arena &operator=(const Arena &) = delete; | Arena &operator=(const Arena &) = delete; | ||||
| ~Arena() override = default; | |||||
| ~Arena() override { | |||||
| if (ptr_ != nullptr) { | |||||
| free(ptr_); | |||||
| } | |||||
| ptr_ = nullptr; | |||||
| } | |||||
| /// As a derived class of MemoryPool, we have to implement the following. | /// As a derived class of MemoryPool, we have to implement the following. | ||||
| /// But we simply transfer the call to the implementation class | /// But we simply transfer the call to the implementation class | ||||
| @@ -141,7 +146,7 @@ class Arena : public MemoryPool { | |||||
| protected: | protected: | ||||
| mutable std::mutex mux_; | mutable std::mutex mux_; | ||||
| std::unique_ptr<ArenaImpl> impl_; | std::unique_ptr<ArenaImpl> impl_; | ||||
| MemGuard<uint8_t> mem_; | |||||
| void *ptr_; | |||||
| size_t size_in_MB_; | size_t size_in_MB_; | ||||
| explicit Arena(size_t val_in_MB = 4096); | explicit Arena(size_t val_in_MB = 4096); | ||||