Loading...
Searching...
No Matches
cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc > Class Template Reference
Small C++ Template Library

Basic slab allocator. More...

`#include <slab_alloc>`

Inheritance diagram for cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >:
Collaboration diagram for cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >:

## Data Structures

struct | Slab_i
| Type of a slab. More...

## Public Types

enum | { object_size = Obj_size , slab_size = Slab_size , objects_per_slab = (Slab_size - sizeof(Slab_head)) / object_size , max_free_slabs = Max_free }
typedef Alloc< Slab_i > | Slab_alloc
| Type of the backend allocator.

## Public Member Functions

void * | alloc () noexcept
| Allocate a new object.
void | free (void *_o) noexcept
| Free the given object (_o).
unsigned | total_objects () const noexcept
| Get the total number of objects managed by the slab allocator.
unsigned | free_objects () const noexcept
| Get the number of objects which can be allocated before a new empty slab needs to be added to the slab allocator.

## Detailed Description

template<int Obj_size, int Slab_size = L4_PAGESIZE, int Max_free = 2, template< typename A > class Alloc = New_allocator>
class cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >

Basic slab allocator.

Template Parameters

  Obj_size | The size of the objects managed by the allocator (in bytes).
  Slab_size | The size of a slab (in bytes).
  Max_free | The maximum number of free slabs. When this limit is reached slabs are freed, provided that the backend allocator supports allocated memory to be freed.
  Alloc | The backend allocator used to allocate slabs.

Definition at line 31 of file slab_alloc.

## Member Enumeration Documentation

## anonymous enum

template<int Obj_size, int Slab_size = L4_PAGESIZE, int Max_free = 2, template< typename A > class Alloc = New_allocator>

anonymous enum

Enumerator
object_size | Size of an object.
slab_size | Size of a slab.
objects_per_slab | Objects per slab.
max_free_slabs | Maximum number of free slabs.

Definition at line 65 of file slab_alloc.

## Member Function Documentation

## alloc()

template<int Obj_size, int Slab_size = L4_PAGESIZE, int Max_free = 2, template< typename A > class Alloc = New_allocator>

void * cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::alloc | ( |  | ) |

inlinenoexcept

Allocate a new object.

Returns
  A pointer to the new object if the allocation succeeds, or 0 on failure to acquire memory from the backend allocator when the slab cache memory is already exhausted.

Note
  The user is responsible for initializing the object.

Definition at line 207 of file slab_alloc.

## free()

template<int Obj_size, int Slab_size = L4_PAGESIZE, int Max_free = 2, template< typename A > class Alloc = New_allocator>

void cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::free | ( | void * | _o | ) |

inlinenoexcept

Free the given object (_o).

Precondition
  The object must have been allocated with this allocator.

Definition at line 246 of file slab_alloc.

## free_objects()

template<int Obj_size, int Slab_size = L4_PAGESIZE, int Max_free = 2, template< typename A > class Alloc = New_allocator>

unsigned cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::free_objects | ( |  | ) | const

inlinenoexcept

Get the number of objects which can be allocated before a new empty slab needs to be added to the slab allocator.

Returns
  The number of free objects in the slab allocator.

Definition at line 308 of file slab_alloc.

## total_objects()

template<int Obj_size, int Slab_size = L4_PAGESIZE, int Max_free = 2, template< typename A > class Alloc = New_allocator>

unsigned cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::total_objects | ( |  | ) | const

inlinenoexcept

Get the total number of objects managed by the slab allocator.

Returns
  The number of objects managed by the allocator (including the free objects).

Definition at line 299 of file slab_alloc.

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

- l4/cxx/slab_alloc