0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Hypertable::PageArena< CharT, PageAllocatorT > Class Template Reference

The PageArena allocator is simple and fast, avoiding individual mallocs/frees. More...

#include <PageArena.h>

Inheritance diagram for Hypertable::PageArena< CharT, PageAllocatorT >:
Inheritance graph
[legend]
Collaboration diagram for Hypertable::PageArena< CharT, PageAllocatorT >:
Collaboration graph
[legend]

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

Pagealloc_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

Pagem_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
 

Detailed Description

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
class Hypertable::PageArena< CharT, PageAllocatorT >

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.

Member Typedef Documentation

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
typedef std::set<Page*, LtPageRemain> Hypertable::PageArena< CharT, PageAllocatorT >::GappyPages
private

a list of pages with gaps, sorted by gap size

Definition at line 120 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
typedef PageArena<CharT, PageAllocatorT> Hypertable::PageArena< CharT, PageAllocatorT >::Self
private

Definition at line 76 of file PageArena.h.

Constructor & Destructor Documentation

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
Hypertable::PageArena< CharT, PageAllocatorT >::PageArena ( size_t  page_size = DEFAULT_PAGE_SIZE,
const PageAllocatorT &  alloc = PageAllocatorT() 
)
inline

Constructor; creates a new PageArena.

Parameters
page_sizeSize (in bytes) of the allocated pages
allocThe allocator for the pages

Definition at line 189 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
Hypertable::PageArena< CharT, PageAllocatorT >::~PageArena ( )
inline

Destructor releases the whole memory and invalidates all allocated objects.

Definition at line 200 of file PageArena.h.

Member Function Documentation

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
CharT* Hypertable::PageArena< CharT, PageAllocatorT >::alloc ( size_t  sz)
inline

Allocate sz bytes.

Definition at line 216 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
CharT* Hypertable::PageArena< CharT, PageAllocatorT >::alloc_big ( size_t  sz)
inlineprivate

Definition at line 177 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
Page* Hypertable::PageArena< CharT, PageAllocatorT >::alloc_page ( size_t  sz,
bool  prepend = true 
)
inlineprivate

Allocates a page of size sz.

Definition at line 145 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
std::ostream& Hypertable::PageArena< CharT, PageAllocatorT >::dump_stat ( std::ostream &  out) const
inline

Write allocator statistics to output stream.

Parameters
outOutput stream
Returns
Output stream

Definition at line 344 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
CharT* Hypertable::PageArena< CharT, PageAllocatorT >::dup ( const CharT *  s)
inline

Duplicate a null terminated string; memory is allocated from the pool.

Parameters
sThe original string which is duplicated
Returns
The new string, or NULL if the original string also pointed to NULL

Definition at line 274 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
CharT* Hypertable::PageArena< CharT, PageAllocatorT >::dup ( const std::string &  s)
inline

Duplicate a std::string; memory is allocated from the pool.

Parameters
sThe original string which is duplicated
Returns
The new string

Definition at line 289 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
CharT* Hypertable::PageArena< CharT, PageAllocatorT >::dup ( const void *  s,
size_t  len 
)
inline

Duplicate a buffer of size len; memory is allocated from the pool.

Parameters
sPointer to the buffer
lenSize of the buffer
Returns
A duplicate of the buffer, or NULL if s also pointed to NULL

Definition at line 299 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
void Hypertable::PageArena< CharT, PageAllocatorT >::ensure_cur_page ( )
inlineprivate

Definition at line 166 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
void Hypertable::PageArena< CharT, PageAllocatorT >::free ( )
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.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
bool Hypertable::PageArena< CharT, PageAllocatorT >::is_normal_overflow ( size_t  sz)
inlineprivate

Definition at line 173 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::page_size ( )
inline

Returns the page size.

Definition at line 205 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::pages ( ) const
inline

Statistic accessors - returns number of allocated pages.

Definition at line 354 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
CharT* Hypertable::PageArena< CharT, PageAllocatorT >::realloc ( void *  p,
size_t  oldsz,
size_t  newsz 
)
inline

Realloc for newsz bytes.

Definition at line 255 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
void Hypertable::PageArena< CharT, PageAllocatorT >::set_page_size ( size_t  sz)
inline

Sets the page size.

Definition at line 210 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
void Hypertable::PageArena< CharT, PageAllocatorT >::swap ( Self other)
inline

Efficiently swaps the state with another allocator.

Definition at line 329 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::total ( ) const
inline

Statistic accessors - returns total allocated size.

Definition at line 357 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::used ( ) const
inline

Statistic accessors - returns used bytes.

Definition at line 351 of file PageArena.h.

Member Data Documentation

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
Page* Hypertable::PageArena< CharT, PageAllocatorT >::m_cur_page
private

Definition at line 104 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::m_gappy_limit
private

Definition at line 123 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
GappyPages Hypertable::PageArena< CharT, PageAllocatorT >::m_gappy_pages
private

Definition at line 121 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
PageAllocatorT Hypertable::PageArena< CharT, PageAllocatorT >::m_page_allocator
private

total number of bytes occupied by pages

Definition at line 110 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::m_page_limit
private

total number of bytes allocated by users

Definition at line 106 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::m_page_size
private

capacity in bytes of an empty page

Definition at line 107 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::m_pages
private

page size in number of bytes

Definition at line 108 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
struct Hypertable::PageArena::TinyBuffer Hypertable::PageArena< CharT, PageAllocatorT >::m_tinybuf
private
template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::m_total
private

number of pages allocated

Definition at line 109 of file PageArena.h.

template<typename CharT = char, class PageAllocatorT = DefaultPageAllocator>
size_t Hypertable::PageArena< CharT, PageAllocatorT >::m_used
private

Definition at line 105 of file PageArena.h.


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