52 #ifndef ETISS_OBJECTPOOL_H_
53 #define ETISS_OBJECTPOOL_H_
60 #define ETISS_OBJECTPOOL_LOGSIZE 1
61 #define ETISS_OBJECTPOOL_DBG_OBJLIMIT 0
66 template <
typename T,
size_t prealloc_inc = 100>
75 typename std::enable_if<!std::is_base_of<etiss::RefCountedObject<ObjectPool<T>>, T>::value,
void>
::type
80 typename std::enable_if<std::is_base_of<etiss::RefCountedObject<ObjectPool<T>>, T>::value,
void>
::type
83 etiss::helper_allocator_ptr_ref<T, ObjectPool<T>>(obj) = this_;
89 #define alignof(x) __alignof(x)
92 template <
typename T,
size_t prealloc_inc>
120 template <
class Type>
136 for (
auto iter =
areas_.begin(); iter !=
areas_.end(); ++iter)
146 throw std::bad_alloc();
158 for (
size_t i = 0; i < prealloc_inc; ++i)
167 throw std::bad_alloc();
169 #if ETISS_OBJECTPOOL_DBG_OBJLIMIT
171 throw new std::bad_alloc();
175 empty_.push_back((
void *)(&(area[i])));
177 #if ETISS_OBJECTPOOL_LOGSIZE
182 void *area =
empty_.back();
192 throw std::bad_alloc();
203 template <
class U,
class... Args>
206 ::new ((
void *)p) U(std::forward<Args>(
args)...);
207 etiss::internal::ObjectPool_setAllocatorPointer<T>((T *)p,
this);
216 template <
typename T>
217 typename std::enable_if<std::is_base_of<etiss::RefCountedObject<ObjectPool<T>>, T>::value,
bool>
::type decRef(T *ptr)
219 bool ret = helper_decRef<T, typename T::refcount_allocatorT>(ptr);
222 ObjectPool<T> *&pool = etiss::helper_allocator_ptr_ref<T, typename T::refcount_allocatorT>(ptr);
225 throw std::bad_alloc();
240 template <
typename T,
size_t stackallocatedsize = 1>
243 static_assert(std::is_pod<T>::value,
"ExpandingNativeStack can only handle types without constructor/destructor. "
244 "This cannot be fullfilled by non POD objects");
247 T
stackbuf_[stackallocatedsize > 0 ? stackallocatedsize : 1];
295 T *tmp =
new T[new_size];
#define static_assert(x, y)
general configuration and logging
#define ETISS_OBJECTPOOL_DBG_OBJLIMIT
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
implements a stack that may only grow (if needed) and can only contain native types since no destruct...
const T operator[](size_t pos) const
T stackbuf_[stackallocatedsize > 0 ? stackallocatedsize :1]
T operator[](ssize_t pos)
prealloc_inc defines the number of objects that is availabe within ObjectPools memory; default: 100
const T & const_reference
std::set< void * > areas_
ObjectPool(size_t blockElementCount=5000)
ObjectPool(const ObjectPool &alloc)
storage stackstore[prealloc_inc]
ObjectPool(const ObjectPool< U > &alloc)
void construct(U *p, Args &&... args)
const T * address(const T &x) const
void deallocate(T *p, size_t n=1)
T * allocate(size_t n=1, const T *=0)
std::vector< void * > empty_
std::aligned_storage< sizeof(T), alignof(T)>::type storage
std::enable_if<!std::is_base_of< etiss::RefCountedObject< ObjectPool< T > >, T >::value, void >::type ObjectPool_setAllocatorPointer(T *obj, ObjectPool< T > *this_)
empty fallback function
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
std::enable_if< std::is_base_of< etiss::RefCountedObject< ObjectPool< T > >, T >::value, bool >::type decRef(T *ptr)
void log(Verbosity level, std::string msg)
write log message at the given level.