Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

ost::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. Accumulative object memory allocator. More...

#include <misc.h>

Inheritance diagram for ost::MemPager:

ost::Keydata ost::SharedMemPager List of all members.

Public Methods

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


Protected Methods

virtual void * first (size_t size)
 Allocate first workspace from paged memory.

virtual void * alloc (size_t size)
 Allocate memory from either the currently active page, or allocate a new page for the object.

char * first (char *str)
 Allocate a string from the memory pager pool and copy the string into it's new memory area.

char * alloc (char *str)
 Allocate a string from the memory pager pool and copy the string inti it's new memory area.

 MemPager (int pagesize=4096)
 Create a paged memory pool for cumulative storage.

void purge (void)
 purge the current memory pool.

virtual ~MemPager ()
 Delete the memory pool and all allocated memory.


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. Accumulative object memory allocator.

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@ostel.com>


Constructor & Destructor Documentation

ost::MemPager::MemPager int    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:
pagesize  page size to allocate chunks.

virtual ost::MemPager::~MemPager   [protected, virtual]
 

Delete the memory pool and all allocated memory.


Member Function Documentation

char* ost::MemPager::alloc 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:
str  string to allocate and copy into paged memory pool.
Returns:
copy of string from allocated memory.

virtual void* ost::MemPager::alloc size_t    size [protected, virtual]
 

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

Parameters:
size  size of memory to allocate.
Returns:
pointer to allocated memory.

Reimplemented in ost::SharedMemPager.

char* ost::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:
str  string to allocate and copy into paged memory pool.
Returns:
copy of string from allocated memory.

virtual void* ost::MemPager::first size_t    size [protected, virtual]
 

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:
size  size of memory to allocate.
Returns:
pointer to allocated memory.

Reimplemented in ost::SharedMemPager.

int ost::MemPager::getPages void    [inline]
 

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

Returns:
number of pages allocated.

void ost::MemPager::purge void    [protected]
 

purge the current memory pool.

Reimplemented in ost::SharedMemPager.


The documentation for this class was generated from the following file:
Generated on Thu Nov 21 12:28:33 2002 for GNU CommonC++ by doxygen1.2.18