#include <new>
#include <assert.h>
#include <stdlib.h>
#include "class_level_lock.h"
#include "mem_pool_base.h"
Include dependency graph for fixed_mem_pool.h:

Go to the source code of this file.
Classes | |
| class | fixed_mem_pool< _Tp > |
| Class template to manipulate a fixed-size memory pool. More... | |
Defines | |
| #define | MEM_POOL_ALIGNMENT 4 |
| Defines the alignment of memory blocks. | |
| #define | DECLARE_FIXED_MEM_POOL(_Cls) |
| Declares the normal (exceptionable) overload of operator new and operator delete. | |
| #define | DECLARE_FIXED_MEM_POOL__NOTHROW(_Cls) |
| Declares the non-exceptionable overload of operator new and operator delete. | |
| #define | DECLARE_FIXED_MEM_POOL__THROW_NOCHECK(_Cls) |
| Declares the exceptionable, non-checking overload of operator new and operator delete. | |
This is a easy-to-use class template for pre-allocated memory pools. The client side needs to do the following things:
class _Cls) definitions
|
|
Value: public: \ static void* operator new(size_t __size) \ { \ assert(__size == sizeof(_Cls)); \ if (void* __ptr = fixed_mem_pool<_Cls>::allocate()) \ return __ptr; \ else \ throw std::bad_alloc(); \ } \ static void operator delete(void* __ptr) \ { \ if (__ptr != NULL) \ fixed_mem_pool<_Cls>::deallocate(__ptr); \ }
|
|
|
Value: public: \ static void* operator new(size_t __size) throw() \ { \ assert(__size == sizeof(_Cls)); \ return fixed_mem_pool<_Cls>::allocate(); \ } \ static void operator delete(void* __ptr) \ { \ if (__ptr != NULL) \ fixed_mem_pool<_Cls>::deallocate(__ptr); \ }
|
|
|
Value: public: \ static void* operator new(size_t __size) \ { \ assert(__size == sizeof(_Cls)); \ return fixed_mem_pool<_Cls>::allocate(); \ } \ static void operator delete(void* __ptr) \ { \ if (__ptr != NULL) \ fixed_mem_pool<_Cls>::deallocate(__ptr); \ }
N.B. Using this macro requires users to explicitly specialize fixed_mem_pool::bad_alloc_handler so that it shall never return
|
|
|
Defines the alignment of memory blocks.
|
1.3.9.1