OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DramArena Class Reference

#include <ArenaAllocator.h>

+ Inheritance diagram for DramArena:
+ Collaboration diagram for DramArena:

Public Member Functions

 DramArena (size_t min_block_size=1ULL<< 32, size_t size_limit=0)
 
 ~DramArena () override
 
void * allocate (size_t num_bytes) override
 
void * allocateAndZero (const size_t size) override
 
size_t bytesUsed () const override
 
size_t totalBytes () const override
 
MemoryType getMemoryType () const override
 
- Public Member Functions inherited from Arena
virtual ~Arena ()
 

Private Attributes

size_t size_limit_
 
size_t size_
 
SysAllocator< void > allocator_
 
std::vector< std::pair< void
*, size_t > > 
allocations_
 

Additional Inherited Members

- Public Types inherited from Arena
enum  MemoryType { MemoryType::DRAM, MemoryType::PMEM }
 

Detailed Description

A naive allocator which calls malloc and maintains a list of allocate pointers for freeing. For development and testing only, where folly is not available. Not for production use.

Definition at line 119 of file ArenaAllocator.h.

Constructor & Destructor Documentation

DramArena::DramArena ( size_t  min_block_size = 1ULL << 32,
size_t  size_limit = 0 
)
inlineexplicit

Definition at line 121 of file ArenaAllocator.h.

122  : size_limit_(size_limit), size_(0) {}
size_t size_
size_t size_limit_
DramArena::~DramArena ( )
inlineoverride

Definition at line 124 of file ArenaAllocator.h.

References allocations_, allocator_, SysAllocator< T >::deallocate(), and size_.

124  {
125  for (auto [ptr, size] : allocations_) {
126  allocator_.deallocate(ptr, 0);
127  size_ -= size;
128  }
129  }
void deallocate(T *p, size_t)
size_t size_
SysAllocator< void > allocator_
std::vector< std::pair< void *, size_t > > allocations_

+ Here is the call graph for this function:

Member Function Documentation

void* DramArena::allocate ( size_t  num_bytes)
inlineoverridevirtual

Implements Arena.

Definition at line 131 of file ArenaAllocator.h.

References SysAllocator< T >::allocate(), allocations_, allocator_, size_, and size_limit_.

Referenced by allocateAndZero().

131  {
132  if (size_limit_ != 0 && size_ + num_bytes > size_limit_) {
133  throw OutOfHostMemory(num_bytes);
134  }
135  auto ret = allocator_.allocate(num_bytes);
136  size_ += num_bytes;
137  allocations_.push_back({ret, num_bytes});
138  return ret;
139  }
T * allocate(size_t count)
size_t size_
size_t size_limit_
SysAllocator< void > allocator_
std::vector< std::pair< void *, size_t > > allocations_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* DramArena::allocateAndZero ( const size_t  size)
inlineoverridevirtual

Implements Arena.

Definition at line 141 of file ArenaAllocator.h.

References allocate().

141  {
142  auto ret = allocate(size);
143  std::memset(ret, 0, size);
144  return ret;
145  }
void * allocate(size_t num_bytes) override

+ Here is the call graph for this function:

size_t DramArena::bytesUsed ( ) const
inlineoverridevirtual

Implements Arena.

Definition at line 147 of file ArenaAllocator.h.

References size_.

147 { return size_; }
size_t size_
MemoryType DramArena::getMemoryType ( ) const
inlineoverridevirtual

Implements Arena.

Definition at line 151 of file ArenaAllocator.h.

References Arena::DRAM.

size_t DramArena::totalBytes ( ) const
inlineoverridevirtual

Implements Arena.

Definition at line 149 of file ArenaAllocator.h.

References size_.

149 { return size_; }
size_t size_

Member Data Documentation

std::vector<std::pair<void*, size_t> > DramArena::allocations_
private

Definition at line 157 of file ArenaAllocator.h.

Referenced by allocate(), and ~DramArena().

SysAllocator<void> DramArena::allocator_
private

Definition at line 156 of file ArenaAllocator.h.

Referenced by allocate(), and ~DramArena().

size_t DramArena::size_
private

Definition at line 155 of file ArenaAllocator.h.

Referenced by allocate(), bytesUsed(), totalBytes(), and ~DramArena().

size_t DramArena::size_limit_
private

Definition at line 154 of file ArenaAllocator.h.

Referenced by allocate().


The documentation for this class was generated from the following file: