Nvwa  1.1
Classes | Namespaces | Macros
static_mem_pool.h File Reference

Header file for the `static' memory pool. More...

#include <new>
#include <stdexcept>
#include <string>
#include <vector>
#include <assert.h>
#include <stddef.h>
#include "_nvwa.h"
#include "c++11.h"
#include "class_level_lock.h"
#include "mem_pool_base.h"
Include dependency graph for static_mem_pool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  nvwa::static_mem_pool_set
 Singleton class to maintain a set of existing instantiations of static_mem_pool. More...
 
class  nvwa::static_mem_pool< _Sz, _Gid >
 Singleton class template to manage the allocation/deallocation of memory blocks of one specific size. More...
 

Namespaces

 nvwa
 Namespace of the nvwa project.
 

Macros

#define DECLARE_STATIC_MEM_POOL(_Cls)
 Declares the normal (throwing) allocation and deallocation functions. More...
 
#define DECLARE_STATIC_MEM_POOL__NOTHROW(_Cls)
 Declares the nothrow allocation and deallocation functions. More...
 
#define DECLARE_STATIC_MEM_POOL_GROUPED(_Cls, _Gid)
 Declares the normal (throwing) allocation and deallocation functions. More...
 
#define DECLARE_STATIC_MEM_POOL_GROUPED__NOTHROW(_Cls, _Gid)
 Declares the nothrow allocation and deallocation functions. More...
 

Detailed Description

Header file for the `static' memory pool.

Date
2014-11-29

Macro Definition Documentation

◆ DECLARE_STATIC_MEM_POOL

#define DECLARE_STATIC_MEM_POOL (   _Cls)
Value:
public: \
static void* operator new(size_t size) \
{ \
assert(size == sizeof(_Cls)); \
void* ptr; \
ptr = NVWA::static_mem_pool<sizeof(_Cls)>:: \
instance_known().allocate(); \
if (ptr == _NULLPTR) \
throw std::bad_alloc(); \
return ptr; \
} \
static void operator delete(void* ptr) \
{ \
if (ptr) \
NVWA::static_mem_pool<sizeof(_Cls)>:: \
instance_known().deallocate(ptr); \
}

Declares the normal (throwing) allocation and deallocation functions.

This macro uses the default group.

Parameters
_Clsclass to use the static_mem_pool
See also
DECLARE_STATIC_MEM_POOL__NOTHROW
DECLARE_STATIC_MEM_POOL_GROUPED
DECLARE_STATIC_MEM_POOL_GROUPED__NOTHROW

◆ DECLARE_STATIC_MEM_POOL__NOTHROW

#define DECLARE_STATIC_MEM_POOL__NOTHROW (   _Cls)
Value:
public: \
static void* operator new(size_t size) _NOEXCEPT \
{ \
assert(size == sizeof(_Cls)); \
return NVWA::static_mem_pool<sizeof(_Cls)>:: \
instance_known().allocate(); \
} \
static void operator delete(void* ptr) \
{ \
if (ptr) \
NVWA::static_mem_pool<sizeof(_Cls)>:: \
instance_known().deallocate(ptr); \
}

Declares the nothrow allocation and deallocation functions.

This macro uses the default group.

Parameters
_Clsclass to use the static_mem_pool
See also
DECLARE_STATIC_MEM_POOL
DECLARE_STATIC_MEM_POOL_GROUPED
DECLARE_STATIC_MEM_POOL_GROUPED__NOTHROW

◆ DECLARE_STATIC_MEM_POOL_GROUPED

#define DECLARE_STATIC_MEM_POOL_GROUPED (   _Cls,
  _Gid 
)
Value:
public: \
static void* operator new(size_t size) \
{ \
assert(size == sizeof(_Cls)); \
void* ptr; \
ptr = NVWA::static_mem_pool<sizeof(_Cls), (_Gid)>:: \
instance_known().allocate(); \
if (ptr == _NULLPTR) \
throw std::bad_alloc(); \
return ptr; \
} \
static void operator delete(void* ptr) \
{ \
if (ptr) \
NVWA::static_mem_pool<sizeof(_Cls), (_Gid)>:: \
instance_known().deallocate(ptr); \
}

Declares the normal (throwing) allocation and deallocation functions.

Users need to specify a group ID.

Parameters
_Clsclass to use the static_mem_pool
_Gidgroup ID (negative to protect multi-threaded access)
See also
DECLARE_STATIC_MEM_POOL
DECLARE_STATIC_MEM_POOL__NOTHROW
DECLARE_STATIC_MEM_POOL_GROUPED__NOTHROW

◆ DECLARE_STATIC_MEM_POOL_GROUPED__NOTHROW

#define DECLARE_STATIC_MEM_POOL_GROUPED__NOTHROW (   _Cls,
  _Gid 
)
Value:
public: \
static void* operator new(size_t size) _NOEXCEPT \
{ \
assert(size == sizeof(_Cls)); \
return NVWA::static_mem_pool<sizeof(_Cls), (_Gid)>:: \
instance_known().allocate(); \
} \
static void operator delete(void* ptr) \
{ \
if (ptr) \
NVWA::static_mem_pool<sizeof(_Cls), (_Gid)>:: \
instance_known().deallocate(ptr); \
}

Declares the nothrow allocation and deallocation functions.

Users need to specify a group ID.

Parameters
_Clsclass to use the static_mem_pool
_Gidgroup ID (negative to protect multi-threaded access)
See also
DECLARE_STATIC_MEM_POOL
DECLARE_STATIC_MEM_POOL__NOTHROW
DECLARE_STATIC_MEM_POOL_GROUPED