112 template <
typename T>
115 if (
sizeof(
T) > Item_Size)
120 return reinterpret_cast<T*
>(allocate_item());
123#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
129 template <
typename T>
147 template <
typename T,
typename T1>
160 template <
typename T,
typename T1,
typename T2>
167 ::new (p)
T(value1, value2);
173 template <
typename T,
typename T1,
typename T2,
typename T3>
174 T*
create(
const T1& value1,
const T2& value2,
const T3& value3)
176 T* p = allocate<T>();
180 ::new (p) T(value1, value2, value3);
186 template <
typename T,
typename T1,
typename T2,
typename T3,
typename T4>
187 T*
create(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
189 T* p = allocate<T>();
193 ::new (p) T(value1, value2, value3, value4);
202 template <
typename T,
typename... Args>
205 T* p = allocate<T>();
221 template <
typename T>
224 if (
sizeof(
T) > Item_Size)
242 release_item((
char*)p);
251 items_initialised = 0;
263 return is_item_in_pool((
const char*)p);
287 return Max_Size - items_allocated;
295 return items_allocated;
304 return items_allocated == 0;
313 return items_allocated == Max_Size;
325 items_initialised(0),
336 char* allocate_item()
338 char* p_value = ETL_NULLPTR;
341 if (items_allocated < Max_Size)
344 if (items_initialised < Max_Size)
346 char* p = p_buffer + (items_initialised * Item_Size);
347 char*
np = p + Item_Size;
348 *
reinterpret_cast<char**
>(p) =
np;
356 if (items_allocated < Max_Size)
359 p_next = *
reinterpret_cast<char**
>(p_next);
364 p_next = ETL_NULLPTR;
369 ETL_ASSERT(
false, ETL_ERROR(pool_no_allocation));
378 void release_item(
char* p_value)
399 ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool));
401 if (items_allocated > 0)
403 if (p_next != ETL_NULLPTR)
406 *(uintptr_t*)p_value =
reinterpret_cast<uintptr_t
>(p_next);
411 *((uintptr_t*)p_value) = 0;
420 ETL_ASSERT_FAIL(ETL_ERROR(pool_no_allocation));
427 bool is_item_in_pool(
const char* p)
const
430 intptr_t distance = p - p_buffer;
431 bool is_within_range = (distance >= 0) && (distance <= intptr_t((Item_Size * Max_Size) - Item_Size));
434#if ETL_IS_DEBUG_BUILD
436 bool is_valid_address = ((distance % Item_Size) == 0);
438 bool is_valid_address =
true;
441 return is_within_range && is_valid_address;
446 ipool& operator =(
const ipool&);
451 uint32_t items_allocated;
452 uint32_t items_initialised;
454 const uint32_t Item_Size;
455 const uint32_t Max_Size;
460#if defined(ETL_POLYMORPHIC_POOL) || defined(ETL_POLYMORPHIC_CONTAINERS)