VAPoR  0.1
Classes | Public Member Functions | Static Public Member Functions | List of all members
VAPoR::BlkMemMgr Class Reference

The VetsUtil BlkMemMgr class. More...

#include <BlkMemMgr.h>

Inheritance diagram for VAPoR::BlkMemMgr:
VetsUtil::MyBase

Public Member Functions

 BlkMemMgr ()
 Initialize a memory allocator. More...
 
virtual ~BlkMemMgr ()
 
void * Alloc (size_t num_blks, bool fill=false)
 Alloc space from memory pool. More...
 
void FreeMem (void *ptr)
 Free memory. More...
 
- Public Member Functions inherited from VetsUtil::MyBase
 MyBase ()
 
const string & getClassName () const
 

Static Public Member Functions

static int RequestMemSize (size_t blk_size, size_t num_blks, bool page_aligned=true)
 Set the size of the memory pool used by the memory allocator. More...
 
static size_t GetBlkSize ()
 
- Static Public Member Functions inherited from VetsUtil::MyBase
static void SetErrMsg (const char *format,...)
 Record a formatted error message. More...
 
static void SetErrMsg (int errcode, const char *format,...)
 Record a formatted error message and an error code. More...
 
static const char * GetErrMsg ()
 
static void SetErrCode (int err_code)
 Record an error code. More...
 
static int GetErrCode ()
 Retrieve the current error code. More...
 
static void SetErrMsgCB (ErrMsgCB_T cb)
 
static ErrMsgCB_T GetErrMsgCB ()
 
static void SetErrMsgFilePtr (FILE *fp)
 
static const FILE * SetErrMsgFilePtr ()
 
static void SetDiagMsg (const char *format,...)
 Record a formatted diagnostic message. More...
 
static const char * GetDiagMsg ()
 
static void SetDiagMsgCB (DiagMsgCB_T cb)
 
static DiagMsgCB_T GetDiagMsgCB ()
 
static void SetDiagMsgFilePtr (FILE *fp)
 
static bool EnableErrMsg (bool enable)
 

Additional Inherited Members

- Public Types inherited from VetsUtil::MyBase
typedef void(* ErrMsgCB_T )(const char *msg, int err_code)
 
typedef void(* DiagMsgCB_T )(const char *msg)
 
- Static Public Attributes inherited from VetsUtil::MyBase
static char * ErrMsg
 
static int ErrCode
 
static int ErrMsgSize
 
static FILE * ErrMsgFilePtr
 
static ErrMsgCB_T ErrMsgCB
 
static char * DiagMsg
 
static int DiagMsgSize
 
static FILE * DiagMsgFilePtr
 
static DiagMsgCB_T DiagMsgCB
 
static bool Enabled
 
- Protected Member Functions inherited from VetsUtil::MyBase
void SetClassName (const string &name)
 

Detailed Description

The VetsUtil BlkMemMgr class.

Author
John Clyne
Version
$Revision$
Date
$Date$

A block-based memory allocator. Allocates contiguous runs of memory blocks from a memory pool of user defined size.

N.B. the memory pool is stored in a static class member and can only be freed by calling RequestMemSize() with a zero value after all instances of this class have been destroyed

Definition at line 26 of file BlkMemMgr.h.

Constructor & Destructor Documentation

VAPoR::BlkMemMgr::BlkMemMgr ( )

Initialize a memory allocator.

Initialize a block-based memory allocator

virtual VAPoR::BlkMemMgr::~BlkMemMgr ( )
virtual

Member Function Documentation

void* VAPoR::BlkMemMgr::Alloc ( size_t  num_blks,
bool  fill = false 
)

Alloc space from memory pool.

Return a pointer to the specified amount of memory from the memory pool

Parameters
[in]num_blksSize of memory region requested in blocks
[in]fillIf true, the allocated memory will be cleared to zero
Return values
ptrA pointer to the requested memory pool
void VAPoR::BlkMemMgr::FreeMem ( void *  ptr)

Free memory.

Frees memory previosly allocated with the Alloc() method.

Parameters
[in]ptrPointer to memory returned by previous call to Alloc().
static size_t VAPoR::BlkMemMgr::GetBlkSize ( )
inlinestatic

Definition at line 72 of file BlkMemMgr.h.

static int VAPoR::BlkMemMgr::RequestMemSize ( size_t  blk_size,
size_t  num_blks,
bool  page_aligned = true 
)
static

Set the size of the memory pool used by the memory allocator.

Initialize a block-based memory allocator. The static memory pool is not changed until the first instance of an object of this class is created, or if there are no instances of objects the memmory pool is changed immediately. The only way to free memory from the static memory pool is to call this static method with either blk_size or num_blks set to zero.

Parameters
[in]blk_sizeSize of a single memory block in bytes
[in]num_blksSize of memory pool in blocks. This is the maximum amount that will be available through subsequent Alloc() calls.
[in]page_alignedIf true, start address of memory pool will be page aligned

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