L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc > Class Template Reference

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_iSlab_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_sizeThe size of the objects managed by the allocator (in bytes).
Slab_sizeThe size of a slab (in bytes).
Max_freeThe maximum number of free slabs. When this limit is reached slabs are freed, provided that the backend allocator supports allocated memory to be freed.
AllocThe backend allocator used to allocate slabs.

Definition at line 42 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 76 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 218 of file slab_alloc.

References cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::free(), cxx::H_list< T, POLICY >::push_front(), and cxx::H_list< T, POLICY >::remove().

Referenced by cxx::Base_slab_static< Obj_size, Slab_size, Max_free, Alloc >::alloc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 257 of file slab_alloc.

References cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::max_free_slabs, cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::objects_per_slab, cxx::H_list< T, POLICY >::push_front(), cxx::H_list< T, POLICY >::remove(), and cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::slab_size.

Referenced by cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::alloc(), and cxx::Base_slab_static< Obj_size, Slab_size, Max_free, Alloc >::free().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 319 of file slab_alloc.

References cxx::Bits::Basic_list< POLICY >::begin(), cxx::Bits::Basic_list< POLICY >::end(), and cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::objects_per_slab.

Referenced by cxx::Base_slab_static< Obj_size, Slab_size, Max_free, Alloc >::free_objects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 310 of file slab_alloc.

References cxx::Base_slab< Obj_size, Slab_size, Max_free, Alloc >::objects_per_slab.

Referenced by cxx::Base_slab_static< Obj_size, Slab_size, Max_free, Alloc >::total_objects().

+ Here is the caller graph for this function:

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