Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
Arena Class Reference

An arena manages a contiguous region of memory by dividing it into chunks. More...

#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 ()
 
 Arena (const Arena &other)=delete
 
Arenaoperator= (const Arena &)=delete
 
voidalloc (size_t size)
 Allocate size bytes from this arena.
 
void free (void *ptr)
 Free a previously allocated chunk of memory.
 
Stats stats () const
 Get arena usage statistics.
 
bool addressInArena (void *ptr) const
 Return whether a pointer points inside this arena.
 

Private Types

typedef std::multimap< size_t, char * > SizeToChunkSortedMap
 
typedef std::unordered_map< char *, SizeToChunkSortedMap::const_iterator > ChunkToSizeMap
 

Private Attributes

SizeToChunkSortedMap size_to_free_chunk
 Map to enable O(log(n)) best-fit allocation, as it's sorted by size.
 
ChunkToSizeMap chunks_free
 Map from begin of free chunk to its node in size_to_free_chunk.
 
ChunkToSizeMap chunks_free_end
 Map from end of free chunk to its node in size_to_free_chunk.
 
std::unordered_map< char *, size_tchunks_used
 Map from begin of used chunk to its size.
 
charbase
 Base address of arena.
 
charend
 End address of arena.
 
size_t alignment
 Minimum chunk alignment.
 

Detailed Description

An arena manages a contiguous region of memory by dividing it into chunks.

Definition at line 50 of file lockedpool.h.

Member Typedef Documentation

◆ ChunkToSizeMap

typedef std::unordered_map<char *, SizeToChunkSortedMap::const_iterator> Arena::ChunkToSizeMap
private

Definition at line 101 of file lockedpool.h.

◆ SizeToChunkSortedMap

typedef std::multimap<size_t, char *> Arena::SizeToChunkSortedMap
private

Definition at line 96 of file lockedpool.h.

Constructor & Destructor Documentation

◆ Arena() [1/2]

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

Definition at line 46 of file lockedpool.cpp.

Here is the call graph for this function:

◆ ~Arena()

Arena::~Arena ( )
virtual

Definition at line 55 of file lockedpool.cpp.

◆ Arena() [2/2]

Arena::Arena ( const Arena other)
delete

Member Function Documentation

◆ addressInArena()

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 93 of file lockedpool.h.

◆ alloc()

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.

Here is the call graph for this function:

◆ free()

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 98 of file lockedpool.cpp.

Here is the call graph for this function:

◆ operator=()

Arena & Arena::operator= ( const Arena )
delete

◆ stats()

Arena::Stats Arena::stats ( ) const

Get arena usage statistics.

Definition at line 135 of file lockedpool.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ alignment

size_t Arena::alignment
private

Minimum chunk alignment.

Definition at line 115 of file lockedpool.h.

◆ base

char* Arena::base
private

Base address of arena.

Definition at line 111 of file lockedpool.h.

◆ chunks_free

ChunkToSizeMap Arena::chunks_free
private

Map from begin of free chunk to its node in size_to_free_chunk.

Definition at line 103 of file lockedpool.h.

◆ chunks_free_end

ChunkToSizeMap Arena::chunks_free_end
private

Map from end of free chunk to its node in size_to_free_chunk.

Definition at line 105 of file lockedpool.h.

◆ chunks_used

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

Map from begin of used chunk to its size.

Definition at line 108 of file lockedpool.h.

◆ end

char* Arena::end
private

End address of arena.

Definition at line 113 of file lockedpool.h.

◆ size_to_free_chunk

SizeToChunkSortedMap Arena::size_to_free_chunk
private

Map to enable O(log(n)) best-fit allocation, as it's sorted by size.

Definition at line 98 of file lockedpool.h.


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