The PageArena allocator is simple and fast, avoiding individual mallocs/frees. More...
#include <PageArena.h>
Classes | |
struct | LtPageRemain |
predicate which sorts by size More... | |
struct | Page |
A structure to manage a single memory page which is used to allocate smaller memory chunks. More... | |
struct | TinyBuffer |
A small buffer (128 bytes) to satisfy very small memory allocations without allocating a page from the heap. More... | |
Public Member Functions | |
PageArena (size_t page_size=DEFAULT_PAGE_SIZE, const PageAllocatorT &alloc=PageAllocatorT()) | |
Constructor; creates a new PageArena. More... | |
~PageArena () | |
Destructor releases the whole memory and invalidates all allocated objects. More... | |
size_t | page_size () |
Returns the page size. More... | |
void | set_page_size (size_t sz) |
Sets the page size. More... | |
CharT * | alloc (size_t sz) |
Allocate sz bytes. More... | |
CharT * | realloc (void *p, size_t oldsz, size_t newsz) |
Realloc for newsz bytes. More... | |
CharT * | dup (const CharT *s) |
Duplicate a null terminated string; memory is allocated from the pool. More... | |
CharT * | dup (const std::string &s) |
Duplicate a std::string; memory is allocated from the pool. More... | |
CharT * | dup (const void *s, size_t len) |
Duplicate a buffer of size len; memory is allocated from the pool. More... | |
void | free () |
Free the whole arena. More... | |
void | swap (Self &other) |
Efficiently swaps the state with another allocator. More... | |
std::ostream & | dump_stat (std::ostream &out) const |
Write allocator statistics to output stream. More... | |
size_t | used () const |
Statistic accessors - returns used bytes. More... | |
size_t | pages () const |
Statistic accessors - returns number of allocated pages. More... | |
size_t | total () const |
Statistic accessors - returns total allocated size. More... | |
Private Types | |
enum | { DEFAULT_PAGE_SIZE = 8192 } |
The default page size is 8 kb. More... | |
typedef PageArena< CharT, PageAllocatorT > | Self |
typedef std::set< Page *, LtPageRemain > | GappyPages |
a list of pages with gaps, sorted by gap size More... | |
Private Member Functions | |
Page * | alloc_page (size_t sz, bool prepend=true) |
Allocates a page of size sz. More... | |
void | ensure_cur_page () |
bool | is_normal_overflow (size_t sz) |
CharT * | alloc_big (size_t sz) |
Private Attributes | |
Page * | m_cur_page |
size_t | m_used |
size_t | m_page_limit |
total number of bytes allocated by users More... | |
size_t | m_page_size |
capacity in bytes of an empty page More... | |
size_t | m_pages |
page size in number of bytes More... | |
size_t | m_total |
number of pages allocated More... | |
PageAllocatorT | m_page_allocator |
total number of bytes occupied by pages More... | |
GappyPages | m_gappy_pages |
size_t | m_gappy_limit |
struct Hypertable::PageArena::TinyBuffer | m_tinybuf |
The PageArena allocator is simple and fast, avoiding individual mallocs/frees.
Good for usage patterns that just load, use and free the entire container repeatedly.
Definition at line 69 of file PageArena.h.
|
private |
a list of pages with gaps, sorted by gap size
Definition at line 120 of file PageArena.h.
|
private |
Definition at line 76 of file PageArena.h.
|
inline |
Constructor; creates a new PageArena.
page_size | Size (in bytes) of the allocated pages |
alloc | The allocator for the pages |
Definition at line 189 of file PageArena.h.
|
inline |
Destructor releases the whole memory and invalidates all allocated objects.
Definition at line 200 of file PageArena.h.
|
inline |
Allocate sz bytes.
Definition at line 216 of file PageArena.h.
|
inlineprivate |
Definition at line 177 of file PageArena.h.
|
inlineprivate |
Allocates a page of size sz.
Definition at line 145 of file PageArena.h.
|
inline |
Write allocator statistics to output stream.
out | Output stream |
Definition at line 344 of file PageArena.h.
|
inline |
Duplicate a null terminated string; memory is allocated from the pool.
s | The original string which is duplicated |
Definition at line 274 of file PageArena.h.
|
inline |
Duplicate a std::string; memory is allocated from the pool.
s | The original string which is duplicated |
Definition at line 289 of file PageArena.h.
|
inline |
Duplicate a buffer of size len; memory is allocated from the pool.
s | Pointer to the buffer |
len | Size of the buffer |
Definition at line 299 of file PageArena.h.
|
inlineprivate |
Definition at line 166 of file PageArena.h.
|
inline |
Free the whole arena.
This releases the total memory allocated by the arena and invalidates all pointers that were previously allocated. This is implicitely called in the destructor.
Definition at line 312 of file PageArena.h.
|
inlineprivate |
Definition at line 173 of file PageArena.h.
|
inline |
Returns the page size.
Definition at line 205 of file PageArena.h.
|
inline |
Statistic accessors - returns number of allocated pages.
Definition at line 354 of file PageArena.h.
|
inline |
Realloc for newsz bytes.
Definition at line 255 of file PageArena.h.
|
inline |
Sets the page size.
Definition at line 210 of file PageArena.h.
|
inline |
Efficiently swaps the state with another allocator.
Definition at line 329 of file PageArena.h.
|
inline |
Statistic accessors - returns total allocated size.
Definition at line 357 of file PageArena.h.
|
inline |
Statistic accessors - returns used bytes.
Definition at line 351 of file PageArena.h.
|
private |
Definition at line 104 of file PageArena.h.
|
private |
Definition at line 123 of file PageArena.h.
|
private |
Definition at line 121 of file PageArena.h.
|
private |
total number of bytes occupied by pages
Definition at line 110 of file PageArena.h.
|
private |
total number of bytes allocated by users
Definition at line 106 of file PageArena.h.
|
private |
capacity in bytes of an empty page
Definition at line 107 of file PageArena.h.
|
private |
page size in number of bytes
Definition at line 108 of file PageArena.h.
|
private |
|
private |
number of pages allocated
Definition at line 109 of file PageArena.h.
|
private |
Definition at line 105 of file PageArena.h.