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 Types | Private Attributes
StackPager Class Reference

The StackPager provides a repository to stash and retrieve working data in last-in-first-out order. More...

#include <misc.h>

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

Data Structures

struct  frame
 

Public Member Functions

 StackPager (size_t pagesize)
 Create a lifo pager as a mempager. More...
 
void * push (const void *object, size_t size)
 Push an arbitrary object onto the stack. More...
 
void * push (const char *string)
 Push a string onto the stack. More...
 
void * pull (void)
 Retrieve next object from stack. More...
 
void purge (void)
 Purge the stack of all objects and memory allocations. More...
 

Protected Member Functions

virtual void * first (size_t size)
 Allocate first workspace from paged memory. More...
 
char * first (char *str)
 Allocate a string from the memory pager pool and copy the string into it's new memory area. 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 * alloc (const char *str)
 Allocate a string from the memory pager pool and copy the string inti it's new memory area. More...
 
void clean (void)
 Clean for memory cleanup before exiting. More...
 
int getPages (void)
 Return the total number of pages that have been allocated for this memory pool. More...
 

Private Types

typedef struct StackPager::frame frame_t
 

Private Attributes

frame_tstack
 

Detailed Description

The StackPager provides a repository to stash and retrieve working data in last-in-first-out order.

The use of a mempager to support it's operation allows storage of arbitrary sized objects with no fixed limit.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m last in first out object pager.

Definition at line 194 of file misc.h.

Member Typedef Documentation

typedef struct StackPager::frame StackPager::frame_t
private

Constructor & Destructor Documentation

StackPager::StackPager ( size_t  pagesize)

Create a lifo pager as a mempager.

Parameters
pagesizefor memory allocation

Member Function Documentation

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

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

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

Clean for memory cleanup before exiting.

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

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

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

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* StackPager::pull ( void  )

Retrieve next object from stack.

Returns
object.
void StackPager::purge ( void  )

Purge the stack of all objects and memory allocations.

void* StackPager::push ( const void *  object,
size_t  size 
)

Push an arbitrary object onto the stack.

Returns
stack memory location.
Parameters
objectpointer to data
sizeof data.
void* StackPager::push ( const char *  string)

Push a string onto the stack.

Returns
stack memory location.
Parameters
stringpointer.

Field Documentation

frame_t* StackPager::stack
private

Definition at line 202 of file misc.h.


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