Pyrogenesis  trunk
Classes | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
HeaderlessAllocator Class Reference

(header-less) pool-based heap allocator provides Allocate and Deallocate without requiring in-band headers; this is useful when allocating page-aligned I/O buffers (headers would waste an entire page per buffer) More...

#include <headerless.h>

Collaboration diagram for HeaderlessAllocator:
Collaboration graph
[legend]

Classes

class  Impl
 

Public Member Functions

 HeaderlessAllocator (size_t poolSize)
 
void Reset ()
 restore the original state (as if newly constructed). More...
 
NOTHROW_DECLARE void * Allocate (size_t size)
 
void Deallocate (void *p, size_t size)
 deallocate memory. More...
 
void Validate () const
 perform sanity checks; ensure allocator state is consistent. More...
 

Static Public Attributes

static const size_t allocationAlignment = 16
 
static const size_t minAllocationSize = 128
 

Private Attributes

shared_ptr< Implimpl
 

Detailed Description

(header-less) pool-based heap allocator provides Allocate and Deallocate without requiring in-band headers; this is useful when allocating page-aligned I/O buffers (headers would waste an entire page per buffer)

policy:

note: this module basically implements a (rather complex) freelist and could be made independent of the Pool allocation scheme. however, reading neighboring boundary tags may cause segmentation violations; knowing the bounds of valid committed memory (i.e. Pool extents) avoids this.

Constructor & Destructor Documentation

HeaderlessAllocator::HeaderlessAllocator ( size_t  poolSize)
Parameters
poolSizemaximum amount of memory that can be allocated. this much virtual address space is reserved up-front (see Pool).

Member Function Documentation

NOTHROW_DEFINE void * HeaderlessAllocator::Allocate ( size_t  size)
Parameters
size[bytes] (= minAllocationSize + i*allocationAlignment). (this allocator is designed for requests on the order of several KiB)
Returns
allocated memory or 0 if the pool is too fragmented or full.
void HeaderlessAllocator::Deallocate ( void *  p,
size_t  size 
)

deallocate memory.

Parameters
pmust be exactly as returned by Allocate (in particular, evenly divisible by allocationAlignment)
sizemust be exactly as specified to Allocate.
void HeaderlessAllocator::Reset ( )

restore the original state (as if newly constructed).

this includes reclaiming all extant allocations.

void HeaderlessAllocator::Validate ( ) const

perform sanity checks; ensure allocator state is consistent.

Member Data Documentation

const size_t HeaderlessAllocator::allocationAlignment = 16
static
shared_ptr<Impl> HeaderlessAllocator::impl
private
const size_t HeaderlessAllocator::minAllocationSize = 128
static

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