My Project
NPLStateMemAllocator.h
1 #pragma once
2 
3 #include "math/ParaMath.h"
4 #include <boost/pool/object_pool.hpp>
5 
6 namespace NPL
7 {
8 #ifndef PARAENGINE_MOBILE
9 
16  extern void * npl_mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize);
17 
25  extern void * npl_mem_dl_alloc(void *ud, void *ptr, size_t osize, size_t nsize);
26 #endif
27 
33  {
34  public:
35  typedef boost::pool<> pool_type;
37  const static int s_pool_init_size_bytes = 32; // default 32
39  const static int s_pool_init_size = 5; // default 5
41  const static int s_pool_count = 4; //default 4
42 
43  private:
45  pool_type * m_mem_pools[s_pool_count];
46 
47  public:
49 
51 
53  inline void* allocate(void *ptr, size_t nsize)
54  {
55  return reallocate(0, 0, nsize);
56  }
57 
59  void* reallocate(void *ptr, size_t osize, size_t nsize);
60 
62  void deallocate(void* const ptr, const size_t n);
63  };
64 }// NPL
define this to enable debugging of NPL code in visual studio
Definition: INPL.h:9
static const int s_pool_init_size
this should be log2(s_pool_init_size_bytes)
Definition: NPLStateMemAllocator.h:39
void * allocate(void *ptr, size_t nsize)
allocate a new buffer
Definition: NPLStateMemAllocator.h:53
static const int s_pool_count
how many free lists are there in the pool.
Definition: NPLStateMemAllocator.h:41
memory allocator for NPL runtime state.
Definition: NPLStateMemAllocator.h:32
void * npl_mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
this function can be provided as Lua memory allocator using CNPLStateMemAllocator e...
Definition: NPLStateMemAllocator.cpp:51
static const int s_pool_init_size_bytes
the initial smallest fixed sized chunk that the memory pool will create.
Definition: NPLStateMemAllocator.h:37
void deallocate(void *const ptr, const size_t n)
free an old buffer.
Definition: NPLStateMemAllocator.cpp:173
void * reallocate(void *ptr, size_t osize, size_t nsize)
reallocate a buffer, old buffer content are copied to new buffer is necessary
Definition: NPLStateMemAllocator.cpp:87
void * npl_mem_dl_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
this function can be provided as Lua memory allocator using dl_malloc e.g.
Definition: NPLStateMemAllocator.cpp:20