µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches

C++ API memory pools definitions. More...

Classes

class  os::rtos::memory_pool::attributes
 Memory pool attributes. More...
 
class  os::rtos::memory_pool
 Synchronised memory pool, using the default RTOS allocator. More...
 
class  os::rtos::memory_pool_allocated< Allocator >
 Template of a synchronised memory pool with allocator. More...
 
class  os::rtos::memory_pool_inclusive< T, N >
 Template of a synchronised memory pool with block type and local storage. More...
 
class  os::rtos::memory_pool_typed< T, Allocator >
 Template of a synchronised memory pool with block type and allocator. More...
 

Typedefs

using os::rtos::memory_pool::size_t = uint16_t
 Type of memory pool size storage.
 

Variables

static const attributes os::rtos::memory_pool::initializer
 Default memory pool initialiser.
 
static constexpr memory_pool::size_t os::rtos::memory_pool::max_size
 Maximum pool size.
 

Detailed Description

C++ API memory pools definitions.

Examples
typedef struct my_blk_s
{
int i;
const char* s;
} my_blk_t;
int
os_main (int argc, char* argv[])
{
my_blk_t* blk;
// Classic usage; block size and cast to char* must be supplied manually.
{
memory_pool cp1
{ 3, sizeof(my_blk_t) };
blk = static_cast<my_blk_t*> (cp1.alloc ());
cp1.free (blk);
blk = static_cast<my_blk_t*> (cp1.try_alloc ());
cp1.free (blk);
blk = static_cast<my_blk_t*> (cp1.timed_alloc (1));
cp1.free (blk);
memory_pool cp2
{ "cp2", 3, sizeof(my_blk_t) };
blk = static_cast<my_blk_t*> (cp2.alloc ());
cp2.free (blk);
}
// --------------------------------------------------------------------------
// Template usage; block size and cast are supplied automatically.
// Define a custom queue type parametrised with the
// message type.
using My_pool = memory_pool_typed<my_blk_t>;
{
My_pool tp1
{ 7 };
blk = tp1.alloc ();
tp1.free (blk);
blk = tp1.try_alloc ();
tp1.free (blk);
blk = tp1.timed_alloc (1);
tp1.free (blk);
My_pool tp2
{ "tp2", 7 };
blk = tp2.alloc ();
tp2.free (blk);
}
// --------------------------------------------------------------------------
// Allocated template usage; block size is supplied automatically.
// Define a custom pool type parametrised with the
// block type and the pool size.
using My_inclusive_pool = memory_pool_inclusive<my_blk_t, 4>;
{
// The space for the pool is allocated inside the pool
// object, in this case on the stack.
My_inclusive_pool sp1;
blk = sp1.alloc ();
sp1.free (blk);
blk = sp1.try_alloc ();
sp1.free (blk);
blk = sp1.timed_alloc (1);
sp1.free (blk);
My_inclusive_pool sp2
{ "sp2" };
blk = sp2.alloc ();
sp2.free (blk);
}
}
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.

Typedef Documentation

◆ size_t

Type of memory pool size storage.

A numeric value that can hold the maximum size of the memory pool, usually a 16-bits unsigned value.

Definition at line 82 of file os-mempool.h.

Variable Documentation

◆ initializer

const memory_pool::attributes os::rtos::memory_pool::initializer
static

Default memory pool initialiser.

This variable is used by the default constructor.

Definition at line 165 of file os-mempool.h.

◆ max_size

constexpr memory_pool::size_t os::rtos::memory_pool::max_size
staticconstexpr
Initial value:
=
static_cast<memory_pool::size_t> (0 - 1)
uint16_t size_t
Type of memory pool size storage.
Definition os-mempool.h:82

Maximum pool size.

A constant numeric value used to validate the pool size.

Definition at line 90 of file os-mempool.h.