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);
295 return Max_Size - items_allocated;
303 return items_allocated;
312 return items_allocated == 0;
321 return items_allocated == Max_Size;
333 items_initialised(0),
344 char* allocate_item()
346 char* p_value = ETL_NULLPTR;
349 if (items_allocated < Max_Size)
352 if (items_initialised < Max_Size)
354 char* p = p_buffer + (items_initialised * Item_Size);
355 char*
np = p + Item_Size;
356 *
reinterpret_cast<char**
>(p) =
np;
364 if (items_allocated < Max_Size)
367 p_next = *
reinterpret_cast<char**
>(p_next);
372 p_next = ETL_NULLPTR;
377 ETL_ASSERT(
false, ETL_ERROR(pool_no_allocation));
386 void release_item(
char* p_value)
389 ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool));
391 if (items_allocated > 0)
394 *(uintptr_t*)p_value =
reinterpret_cast<uintptr_t
>(p_next);
402 ETL_ASSERT_FAIL(ETL_ERROR(pool_no_allocation));
409 bool is_item_in_pool(
const char* p)
const
412 intptr_t distance = p - p_buffer;
413 bool is_within_range = (distance >= 0) && (distance <= intptr_t((Item_Size * Max_Size) - Item_Size));
416#if ETL_IS_DEBUG_BUILD
418 bool is_valid_address = ((distance % Item_Size) == 0);
420 bool is_valid_address =
true;
423 return is_within_range && is_valid_address;
428 ipool& operator =(
const ipool&);
433 uint32_t items_allocated;
434 uint32_t items_initialised;
436 const uint32_t Item_Size;
437 const uint32_t Max_Size;
442#if defined(ETL_POLYMORPHIC_POOL) || defined(ETL_POLYMORPHIC_CONTAINERS)