OmniSciDB  d2f719934e
 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
 
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 114 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 116 of file ArenaAllocator.h.

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

Definition at line 119 of file ArenaAllocator.h.

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

119  {
120  for (auto [ptr, size] : allocations_) {
121  allocator_.deallocate(ptr, 0);
122  size_ -= size;
123  }
124  }
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 126 of file ArenaAllocator.h.

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

Referenced by allocateAndZero().

126  {
127  if (size_limit_ != 0 && size_ + num_bytes > size_limit_) {
128  throw OutOfHostMemory(num_bytes);
129  }
130  auto ret = allocator_.allocate(num_bytes);
131  size_ += num_bytes;
132  allocations_.push_back({ret, num_bytes});
133  return ret;
134  }
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 136 of file ArenaAllocator.h.

References allocate().

136  {
137  auto ret = allocate(size);
138  std::memset(ret, 0, size);
139  return ret;
140  }
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 142 of file ArenaAllocator.h.

References size_.

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

Implements Arena.

Definition at line 144 of file ArenaAllocator.h.

References Arena::DRAM.

Member Data Documentation

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

Definition at line 150 of file ArenaAllocator.h.

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

SysAllocator<void> DramArena::allocator_
private

Definition at line 149 of file ArenaAllocator.h.

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

size_t DramArena::size_
private

Definition at line 148 of file ArenaAllocator.h.

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

size_t DramArena::size_limit_
private

Definition at line 147 of file ArenaAllocator.h.

Referenced by allocate().


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