Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Arena Class Reference

#include <lockedpool.h>

Inheritance diagram for Arena:
[legend]

Classes

struct  Stats
 Memory statistics. More...
 

Public Member Functions

 Arena (void *base, size_t size, size_t alignment)
 
virtual ~Arena ()
 
void * alloc (size_t size)
 Allocate size bytes from this arena. More...
 
void free (void *ptr)
 Free a previously allocated chunk of memory. More...
 
Stats stats () const
 Get arena usage statistics. More...
 
bool addressInArena (void *ptr) const
 Return whether a pointer points inside this arena. More...
 

Private Member Functions

 Arena (const Arena &other)=delete
 
Arenaoperator= (const Arena &)=delete
 

Private Attributes

std::map< char *, size_t > chunks_free
 Map of chunk address to chunk information. More...
 
std::map< char *, size_t > chunks_used
 
char * base
 Base address of arena. More...
 
char * end
 End address of arena. More...
 
size_t alignment
 Minimum chunk alignment. More...
 

Detailed Description

Definition at line 47 of file lockedpool.h.

Constructor & Destructor Documentation

Arena::Arena ( void *  base,
size_t  size,
size_t  alignment 
)

Definition at line 46 of file lockedpool.cpp.

Arena::~Arena ( )
virtual

Definition at line 53 of file lockedpool.cpp.

Arena::Arena ( const Arena other)
privatedelete

Member Function Documentation

bool Arena::addressInArena ( void *  ptr) const
inline

Return whether a pointer points inside this arena.

This returns base <= ptr < (base+size) so only use it for (inclusive) chunk starting addresses.

Definition at line 86 of file lockedpool.h.

void * Arena::alloc ( size_t  size)

Allocate size bytes from this arena.

Returns pointer on success, or 0 if memory is full or the application tried to allocate 0 bytes.

Definition at line 57 of file lockedpool.cpp.

void Arena::free ( void *  ptr)

Free a previously allocated chunk of memory.

Freeing the zero pointer has no effect. Raises std::runtime_error in case of error.

Definition at line 88 of file lockedpool.cpp.

Here is the call graph for this function:

Arena& Arena::operator= ( const Arena )
privatedelete
Arena::Stats Arena::stats ( ) const

Get arena usage statistics.

Definition at line 112 of file lockedpool.cpp.

Here is the call graph for this function:

Member Data Documentation

size_t Arena::alignment
private

Minimum chunk alignment.

Definition at line 101 of file lockedpool.h.

char* Arena::base
private

Base address of arena.

Definition at line 97 of file lockedpool.h.

std::map<char*, size_t> Arena::chunks_free
private

Map of chunk address to chunk information.

This class makes use of the sorted order to merge previous and next chunks during deallocation.

Definition at line 94 of file lockedpool.h.

std::map<char*, size_t> Arena::chunks_used
private

Definition at line 95 of file lockedpool.h.

char* Arena::end
private

End address of arena.

Definition at line 99 of file lockedpool.h.


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