#include <CArena.H>
Public Types | |
enum | { DefaultHunkSize = 1024*1024 } |
The default memory hunk size to grab from the heap. More... | |
Public Member Functions | |
CArena (size_t hunk_size=0) | |
Construct a coalescing memory manager. | |
virtual | ~CArena () |
The destructor. | |
virtual void * | alloc (size_t nbytes) |
Allocate some memory. | |
virtual void | free (void *ap) |
Free up allocated memory. | |
size_t | heap_space_used () const |
The current amount of heap space used by the CArena object. | |
Static Public Member Functions | |
static size_t | align (size_t sz) |
Given a minimum required arena size of sz bytes, this returns the next largest arena size that will hold an integral number of objects of the largest of the types void*, long, double and function pointer. | |
Protected Types | |
typedef std::set< Node > | NL |
Protected Attributes | |
std::vector< void * > | m_alloc |
NL | m_freelist |
NL | m_busylist |
size_t | m_hunk |
size_t | m_used |
Classes | |
class | Node |
This is a coalescing memory manager. It allocates (possibly) large chunks of heap space and apportions it out as requested. It merges together neighboring chunks on each free().
typedef std::set<Node> CArena::NL [protected] |
CArena::CArena | ( | size_t | hunk_size = 0 |
) |
Construct a coalescing memory manager.
`hunk' is the minimum size of hunks of memory to allocate from the heap. If hunk == 0 we use DefaultHunkSize as specified below.
References Arena::align(), BL_ASSERT, DefaultHunkSize, m_hunk, and m_used.
CArena::~CArena | ( | ) | [virtual] |
void * CArena::alloc | ( | size_t | nbytes | ) | [virtual] |
Allocate some memory.
Implements Arena.
References Arena::align(), BL_ASSERT, CArena::Node::block(), m_alloc, m_busylist, m_freelist, m_hunk, m_used, and CArena::Node::size().
void CArena::free | ( | void * | ap | ) | [virtual] |
Free up allocated memory.
Merge neighboring free memory chunks into largest possible chunk.
Implements Arena.
References BL_ASSERT, m_busylist, m_freelist, and CArena::Node::size().
size_t CArena::heap_space_used | ( | ) | const |
size_t Arena::align | ( | size_t | sz | ) | [static, inherited] |
std::vector<void*> CArena::m_alloc [protected] |
NL CArena::m_freelist [protected] |
NL CArena::m_busylist [protected] |
size_t CArena::m_hunk [protected] |
size_t CArena::m_used [protected] |
Referenced by alloc(), CArena(), and heap_space_used().