mirror of
https://github.com/ETLCPP/etl.git
synced 2026-05-01 11:29:09 +08:00
Added pool_ext & generic_pool_ext
This commit is contained in:
parent
494059fd6b
commit
aaa00ca610
1
.gitignore
vendored
1
.gitignore
vendored
@ -325,3 +325,4 @@ test/vs2019/Test2
|
||||
test/vs2019/Debug MSVC - Force C++03
|
||||
test/vs2019/Debug LLVM - No STL
|
||||
test/vs2019/Debug - No STL
|
||||
test/build-make
|
||||
|
||||
@ -190,15 +190,22 @@ namespace etl
|
||||
static ETL_CONSTANT uint32_t Element_Size = sizeof(Element);
|
||||
|
||||
// Should not be copied.
|
||||
generic_pool(const generic_pool&);
|
||||
generic_pool& operator =(const generic_pool&);
|
||||
generic_pool(const generic_pool&) ETL_DELETE;
|
||||
generic_pool& operator =(const generic_pool&) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// A templated abstract pool implementation that uses a fixed size pool.
|
||||
/// The storage for the pool is supplied externally.
|
||||
///\ingroup pool
|
||||
//*************************************************************************
|
||||
template <const size_t VTypeSize, const size_t VAlignment>
|
||||
class generic_pool_ext : public etl::ipool {
|
||||
class generic_pool_ext : public etl::ipool
|
||||
{
|
||||
private:
|
||||
// The pool element.
|
||||
union element_internal {
|
||||
union element_internal
|
||||
{
|
||||
char* next; ///< Pointer to the next free element.
|
||||
char value[VTypeSize]; ///< Storage for value type.
|
||||
typename etl::type_with_alignment<VAlignment>::type dummy; ///< Dummy item to get correct alignment.
|
||||
@ -210,12 +217,15 @@ namespace etl
|
||||
static ETL_CONSTANT size_t ALIGNMENT = VAlignment;
|
||||
static ETL_CONSTANT size_t TYPE_SIZE = VTypeSize;
|
||||
|
||||
using element = typename etl::aligned_storage<sizeof(element_internal), etl::alignment_of<element_internal>::value>::type;
|
||||
typedef typename etl::aligned_storage<sizeof(element_internal), etl::alignment_of<element_internal>::value>::type element;
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
generic_pool_ext(element* buffer, size_t size) : etl::ipool(reinterpret_cast<char*>(&buffer[0]), ELEMENT_INTERNAL_SIZE, size) {}
|
||||
generic_pool_ext(element* buffer, size_t size)
|
||||
: etl::ipool(reinterpret_cast<char*>(&buffer[0]), ELEMENT_INTERNAL_SIZE, size)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Allocate an object from the pool.
|
||||
@ -325,8 +335,8 @@ namespace etl
|
||||
|
||||
private:
|
||||
// Should not be copied.
|
||||
generic_pool_ext(const generic_pool_ext&);
|
||||
generic_pool_ext& operator=(const generic_pool_ext&);
|
||||
generic_pool_ext(const generic_pool_ext&) ETL_DELETE;
|
||||
generic_pool_ext& operator=(const generic_pool_ext&) ETL_DELETE;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -179,8 +179,14 @@ namespace etl
|
||||
pool& operator =(const pool&) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// A templated pool implementation that uses a fixed size pool.
|
||||
/// The storage for the pool is supplied externally.
|
||||
///\ingroup pool
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
class pool_ext : public etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value> {
|
||||
class pool_ext : public etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value>
|
||||
{
|
||||
private:
|
||||
typedef etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value> base_t;
|
||||
|
||||
@ -191,7 +197,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
pool_ext(typename base_t::element* buffer, size_t size) : base_t(buffer, size) {}
|
||||
pool_ext(typename base_t::element* buffer, size_t size)
|
||||
: base_t(buffer, size)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Allocate an object from the pool.
|
||||
@ -200,7 +209,10 @@ namespace etl
|
||||
/// etl::pool_no_allocation if thrown, otherwise a null pointer is returned.
|
||||
/// Static asserts if the specified type is too large for the pool.
|
||||
//*************************************************************************
|
||||
T* allocate() { return base_t::template allocate<T>(); }
|
||||
T* allocate()
|
||||
{
|
||||
return base_t::template allocate<T>();
|
||||
}
|
||||
|
||||
#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
|
||||
//*************************************************************************
|
||||
@ -208,7 +220,10 @@ namespace etl
|
||||
/// If asserts or exceptions are enabled and there are no more free items an
|
||||
/// etl::pool_no_allocation if thrown, otherwise a null pointer is returned.
|
||||
//*************************************************************************
|
||||
T* create() { return base_t::template create<T>(); }
|
||||
T* create()
|
||||
{
|
||||
return base_t::template create<T>();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Allocate storage for an object from the pool and create with 1 parameter.
|
||||
|
||||
@ -8276,6 +8276,7 @@
|
||||
<ClCompile Include="..\test_parity_checksum.cpp" />
|
||||
<ClCompile Include="..\test_pearson.cpp" />
|
||||
<ClCompile Include="..\test_pool.cpp" />
|
||||
<ClCompile Include="..\test_pool_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_quantize.cpp" />
|
||||
<ClCompile Include="..\test_queue_lockable.cpp" />
|
||||
<ClCompile Include="..\test_queue_lockable_small.cpp" />
|
||||
|
||||
@ -3017,6 +3017,9 @@
|
||||
<ClCompile Include="..\test_multi_vector.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_pool_external_buffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user