revert arena code to use malloc

pull/6992/head
Jesse Lee 4 years ago
parent a110e61caf
commit 2b6f8556ca

@ -235,15 +235,15 @@ std::ostream &operator<<(std::ostream &os, const ArenaImpl &s) {
Status Arena::Init() {
try {
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) {
return Status(StatusCode::kOutOfMemory);
}
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) {
RETURN_UNEXPECTED_IF_NULL(p_ba);

@ -104,7 +104,12 @@ class Arena : public MemoryPool {
// Disable copy and assignment constructor
Arena(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.
/// But we simply transfer the call to the implementation class
@ -141,7 +146,7 @@ class Arena : public MemoryPool {
protected:
mutable std::mutex mux_;
std::unique_ptr<ArenaImpl> impl_;
MemGuard<uint8_t> mem_;
void *ptr_;
size_t size_in_MB_;
explicit Arena(size_t val_in_MB = 4096);

Loading…
Cancel
Save