esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
ndnph::Region Class Reference

Region-based memory allocator thats owns memory of NDNph objects. More...

#include <region.hpp>

Inherited by ndnph::StaticRegion< 2048 >, ndnph::StaticRegion< 512 >, ndnph::StaticRegion< 256 >, ndnph::DynamicRegion, and ndnph::StaticRegion< C >.

Public Types

enum  { ALIGNMENT = sizeof(void*) }
 

Public Member Functions

 Region (uint8_t *buf, size_t cap)
 
uint8_t * alloc (size_t size)
 Allocate a buffer with no alignment requirement.
 
uint8_t * allocA (size_t size)
 Allocate a region aligned to multiple of sizeof(void*).
 
bool free (const uint8_t *first, const uint8_t *last)
 Deallocate (part of) last allocated buffer.
 
bool free (const uint8_t *ptr, size_t size)
 
template<typename T , typename... Arg>
T * make (Arg &&... arg)
 Allocate and create an item, and return its pointer.
 
template<typename RefType , typename... Arg>
RefType create (Arg &&... arg)
 Allocate and create an object, and return its reference.
 
void reset ()
 Discard allocated items.
 
size_t available () const
 Compute remaining space for alloc().
 
size_t availableA () const
 Compute remaining space for allocA().
 
size_t size () const
 Compute utilized space.
 

Static Public Member Functions

template<typename T >
static constexpr T sizeofAligned (T size)
 

Protected Member Functions

uint8_t * getArray ()
 

Detailed Description

Region-based memory allocator thats owns memory of NDNph objects.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ALIGNMENT 

Constructor & Destructor Documentation

◆ Region()

ndnph::Region::Region ( uint8_t *  buf,
size_t  cap 
)
inlineexplicit

Member Function Documentation

◆ alloc()

uint8_t * ndnph::Region::alloc ( size_t  size)
inline

Allocate a buffer with no alignment requirement.

◆ allocA()

uint8_t * ndnph::Region::allocA ( size_t  size)
inline

Allocate a region aligned to multiple of sizeof(void*).

◆ available()

size_t ndnph::Region::available ( ) const
inline

Compute remaining space for alloc().

◆ availableA()

size_t ndnph::Region::availableA ( ) const
inline

Compute remaining space for allocA().

◆ create()

template<typename RefType , typename... Arg>
RefType ndnph::Region::create ( Arg &&...  arg)
inline

Allocate and create an object, and return its reference.

Template Parameters
RefTypea subclass of RefRegion<ObjType> , where ObjType is a subclass of InRegion .
Returns
a reference to the created object.
Warning
If `!ref` is true on the returned reference, it indicates allocation failure. Using the reference in that case would cause segmentation fault.

◆ free() [1/2]

bool ndnph::Region::free ( const uint8_t *  first,
const uint8_t *  last 
)
inline

Deallocate (part of) last allocated buffer.

Return values
true[first, last) is either front part of last buffer from alloc(), or back part of last buffer from allocA(), and has been freed.
false[first, last) cannot be freed.

◆ free() [2/2]

bool ndnph::Region::free ( const uint8_t *  ptr,
size_t  size 
)
inline

◆ getArray()

uint8_t * ndnph::Region::getArray ( )
inlineprotected

◆ make()

template<typename T , typename... Arg>
T * ndnph::Region::make ( Arg &&...  arg)
inline

Allocate and create an item, and return its pointer.

◆ reset()

void ndnph::Region::reset ( )
inline

Discard allocated items.

Postcondition
Allocated items are invalidated.

◆ size()

size_t ndnph::Region::size ( ) const
inline

Compute utilized space.

◆ sizeofAligned()

template<typename T >
static constexpr T ndnph::Region::sizeofAligned ( size)
inlinestaticconstexpr

The documentation for this class was generated from the following file: