32 #define THREAD_NUMBER omp_get_thread_num() 33 static const size_t MAXNBTHREADS = 128;
35 #define THREAD_NUMBER 0 36 static const size_t MAXNBTHREADS = 1;
39 static const size_t BUFFOBJ = 20;
72 template <
typename TYPE >
79 inline void *
operator new(
size_t sizeofObj) {
81 inline void *
operator new( size_t ) {
83 assert(
sizeof(TYPE) == sizeofObj);
85 t = getObject(THREAD_NUMBER);
89 inline void operator delete(
void *p ) {
90 _freeObject[THREAD_NUMBER].push_back(p);
93 static std::vector<void * > _freeObject[MAXNBTHREADS];
95 static TYPE* getObject(
size_t threadId) {
98 if (_freeObject[threadId].empty()) {
99 TYPE * p = (TYPE *)malloc(BUFFOBJ *
sizeof(TYPE));
101 for (
size_t j=0; j< BUFFOBJ - 1; ++j) {
102 _freeObject[threadId].push_back((
void *)p);
109 result = (TYPE *)_freeObject[threadId].back();
110 _freeObject[threadId].pop_back();
117 template <
typename TYPE >
118 std::vector<void * > MemoryPool<TYPE>::_freeObject[MAXNBTHREADS];
121 #endif // MEMORYPOOL_H