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

#include <CpuMgrArenaAllocator.h>

+ Inheritance diagram for CpuMgrArenaAllocator:
+ Collaboration diagram for CpuMgrArenaAllocator:

Public Member Functions

 CpuMgrArenaAllocator ()
 
 ~CpuMgrArenaAllocator () override
 
void * allocate (size_t num_bytes) override
 
void * allocateAndZero (const size_t num_bytes) 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

Data_Namespace::DataMgrdata_mgr_
 
std::vector
< Data_Namespace::AbstractBuffer * > 
allocated_buffers_
 
size_t size_
 

Additional Inherited Members

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

Detailed Description

Definition at line 31 of file CpuMgrArenaAllocator.h.

Constructor & Destructor Documentation

CpuMgrArenaAllocator::CpuMgrArenaAllocator ( )

Definition at line 29 of file CpuMgrArenaAllocator.cpp.

CpuMgrArenaAllocator::~CpuMgrArenaAllocator ( )
override

Definition at line 32 of file CpuMgrArenaAllocator.cpp.

References allocated_buffers_, data_mgr_, and Data_Namespace::DataMgr::free().

32  {
33  for (auto buffer : allocated_buffers_) {
34  data_mgr_.free(buffer);
35  }
36 }
std::vector< Data_Namespace::AbstractBuffer * > allocated_buffers_
Data_Namespace::DataMgr & data_mgr_
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:614

+ Here is the call graph for this function:

Member Function Documentation

void * CpuMgrArenaAllocator::allocate ( size_t  num_bytes)
overridevirtual

Implements Arena.

Definition at line 38 of file CpuMgrArenaAllocator.cpp.

References Data_Namespace::DataMgr::alloc(), allocated_buffers_, CHECK, Data_Namespace::CPU_LEVEL, data_mgr_, logger::ERROR, Data_Namespace::AbstractBuffer::getMemoryPtr(), LOG, and size_.

Referenced by allocateAndZero().

38  {
39  if (num_bytes == 0) {
40  return nullptr;
41  }
42  AbstractBuffer* buffer = nullptr;
43  try {
44  buffer = data_mgr_.alloc(Data_Namespace::CPU_LEVEL, 0, num_bytes);
45  } catch (const OutOfMemory& e) {
46  LOG(ERROR) << e.what();
47  throw OutOfHostMemory(num_bytes);
48  }
49  CHECK(buffer);
50  allocated_buffers_.emplace_back(buffer);
51 
52  auto mem_ptr = buffer->getMemoryPtr();
53  CHECK(mem_ptr);
54  size_ += num_bytes;
55  return mem_ptr;
56 }
#define LOG(tag)
Definition: Logger.h:285
virtual int8_t * getMemoryPtr()=0
An AbstractBuffer is a unit of data management for a data manager.
std::vector< Data_Namespace::AbstractBuffer * > allocated_buffers_
Data_Namespace::DataMgr & data_mgr_
#define CHECK(condition)
Definition: Logger.h:291
AbstractBuffer * alloc(const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
Definition: DataMgr.cpp:605

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * CpuMgrArenaAllocator::allocateAndZero ( const size_t  num_bytes)
overridevirtual

Implements Arena.

Definition at line 58 of file CpuMgrArenaAllocator.cpp.

References allocate().

58  {
59  auto ret = allocate(num_bytes);
60  std::memset(ret, 0, num_bytes);
61  return ret;
62 }
void * allocate(size_t num_bytes) override

+ Here is the call graph for this function:

size_t CpuMgrArenaAllocator::bytesUsed ( ) const
overridevirtual

Implements Arena.

Definition at line 64 of file CpuMgrArenaAllocator.cpp.

References size_.

64  {
65  return size_;
66 }
Arena::MemoryType CpuMgrArenaAllocator::getMemoryType ( ) const
overridevirtual

Implements Arena.

Definition at line 72 of file CpuMgrArenaAllocator.cpp.

References Arena::DRAM.

size_t CpuMgrArenaAllocator::totalBytes ( ) const
overridevirtual

Implements Arena.

Definition at line 68 of file CpuMgrArenaAllocator.cpp.

References size_.

68  {
69  return size_;
70 }

Member Data Documentation

std::vector<Data_Namespace::AbstractBuffer*> CpuMgrArenaAllocator::allocated_buffers_
private

Definition at line 49 of file CpuMgrArenaAllocator.h.

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

Data_Namespace::DataMgr& CpuMgrArenaAllocator::data_mgr_
private

Definition at line 48 of file CpuMgrArenaAllocator.h.

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

size_t CpuMgrArenaAllocator::size_
private

Definition at line 50 of file CpuMgrArenaAllocator.h.

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


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