Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Public Member Functions | Protected Member Functions | Private Attributes | Friends
MemPager Class Reference

The memory pager is used to allocate cumulative memory pages for storing object specific "persistant" data that is presumed to persist during the life of a given derived object. More...

#include <misc.h>

Inheritance diagram for MemPager:
Inheritance graph
[legend]
Collaboration diagram for MemPager:
Collaboration graph
[legend]

Data Structures

struct  _page
 

Public Member Functions

int getPages (void)
 Return the total number of pages that have been allocated for this memory pool. More...
 

Protected Member Functions

virtual void * first (size_t size)
 Allocate first workspace from paged memory. More...
 
virtual void * alloc (size_t size)
 Allocate memory from either the currently active page, or allocate a new page for the object. More...
 
char * first (char *str)
 Allocate a string from the memory pager pool and copy the string into it's new memory area. More...
 
char * alloc (const char *str)
 Allocate a string from the memory pager pool and copy the string inti it's new memory area. More...
 
 MemPager (size_t pagesize=4096)
 Create a paged memory pool for cumulative storage. More...
 
void purge (void)
 purge the current memory pool. More...
 
void clean (void)
 Clean for memory cleanup before exiting. More...
 
virtual ~MemPager ()
 Delete the memory pool and all allocated memory. More...
 

Private Attributes

size_t pagesize
 
unsigned int pages
 
struct MemPager::_pagepage
 

Friends

class String
 
class MemPagerObject
 

Detailed Description

The memory pager is used to allocate cumulative memory pages for storing object specific "persistant" data that is presumed to persist during the life of a given derived object.

When the object is destroyed, all accumulated data is automatically purged.

There are a number of odd and specialized utility classes found in Common C++. The most common of these is the "MemPager" class. This is basically a class to enable page-grouped "cumulative" memory allocation; all accumulated allocations are dropped during the destructor. This class has found it's way in a lot of other utility classes in Common C++.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m Accumulative object memory allocator.

Definition at line 91 of file misc.h.

Constructor & Destructor Documentation

MemPager::MemPager ( size_t  pagesize = 4096)
protected

Create a paged memory pool for cumulative storage.

This pool allocates memory in fixed "pagesize" chunks. Ideal performance is achived when the pool size matches the system page size. This pool can only exist in derived objects.

Parameters
pagesizepage size to allocate chunks.
virtual MemPager::~MemPager ( )
protectedvirtual

Delete the memory pool and all allocated memory.

Member Function Documentation

virtual void* MemPager::alloc ( size_t  size)
protectedvirtual

Allocate memory from either the currently active page, or allocate a new page for the object.

Parameters
sizesize of memory to allocate.
Returns
pointer to allocated memory.

Reimplemented in SharedMemPager.

char* MemPager::alloc ( const char *  str)
protected

Allocate a string from the memory pager pool and copy the string inti it's new memory area.

This checks only the last active page for available space before allocating a new page.

Parameters
strstring to allocate and copy into paged memory pool.
Returns
copy of string from allocated memory.
void MemPager::clean ( void  )
protected

Clean for memory cleanup before exiting.

virtual void* MemPager::first ( size_t  size)
protectedvirtual

Allocate first workspace from paged memory.

This method scans all currently allocated blocks for available space before adding new pages and hence is both slower and more efficient.

Parameters
sizesize of memory to allocate.
Returns
pointer to allocated memory.

Reimplemented in SharedMemPager.

char* MemPager::first ( char *  str)
protected

Allocate a string from the memory pager pool and copy the string into it's new memory area.

This method allocates memory by first searching for an available page, and then allocating a new page if no space is found.

Parameters
strstring to allocate and copy into paged memory pool.
Returns
copy of string from allocated memory.
int MemPager::getPages ( void  )
inline

Return the total number of pages that have been allocated for this memory pool.

Returns
number of pages allocated.

Definition at line 181 of file misc.h.

void MemPager::purge ( void  )
protected

purge the current memory pool.

Friends And Related Function Documentation

friend class MemPagerObject
friend

Definition at line 95 of file misc.h.

friend class String
friend

Definition at line 94 of file misc.h.

Field Documentation

struct MemPager::_page * MemPager::page
private
unsigned int MemPager::pages
private

Definition at line 98 of file misc.h.

size_t MemPager::pagesize
private

Definition at line 97 of file misc.h.


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