Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>

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.

Definition at line 49 of file headerless.h.

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).

Definition at line 747 of file headerless.cpp.

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.

Definition at line 757 of file headerless.cpp.

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.

Definition at line 762 of file headerless.cpp.

void HeaderlessAllocator::Reset ( )

restore the original state (as if newly constructed).

this includes reclaiming all extant allocations.

Definition at line 752 of file headerless.cpp.

void HeaderlessAllocator::Validate ( ) const

perform sanity checks; ensure allocator state is consistent.

Definition at line 767 of file headerless.cpp.

Member Data Documentation

const size_t HeaderlessAllocator::allocationAlignment = 16
static

Definition at line 56 of file headerless.h.

shared_ptr<Impl> HeaderlessAllocator::impl
private

Definition at line 95 of file headerless.h.

const size_t HeaderlessAllocator::minAllocationSize = 128
static

Definition at line 60 of file headerless.h.


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