23 #include <l4/cxx/std_alloc> 24 #include <l4/cxx/hlist> 25 #include <l4/sys/consts.h> 38 template<
int Obj_size,
int Slab_size =
L4_PAGESIZE,
39 int Max_free = 2,
template<
typename A>
class Alloc = New_allocator >
58 inline Slab_head()
throw() : num_free(0), free(0), cache(0)
77 Free_o *object(
unsigned obj)
throw()
78 {
return reinterpret_cast<Free_o*
>(_o +
object_size * obj); }
81 struct Slab_i :
public Slab_store,
public Slab_head
88 typedef void Obj_type;
99 void add_slab(Slab_i *s)
throw()
108 Free_o *f = s->free = s->object(0);
111 f->next = s->object(i);
125 Slab_i *s = _alloc.alloc();
136 void shrink()
throw()
138 if (!_alloc.can_free)
143 Slab_i *s = _empty_slabs.
front();
153 : _alloc(alloc), _num_free(0), _num_slabs(0), _full_slabs(0),
154 _partial_slabs(0), _empty_slabs(0)
159 while (!_empty_slabs.
empty())
161 Slab_i *o = _empty_slabs.
front();
165 while (!_partial_slabs.
empty())
167 Slab_i *o = _partial_slabs.
front();
171 while (!_full_slabs.
empty())
173 Slab_i *o = _full_slabs.
front();
179 void *alloc()
throw()
183 free = &_empty_slabs;
185 if (free->
empty() && !grow())
188 Slab_i *s = free->
front();
192 if (free == &_empty_slabs)
205 else if (free == &_empty_slabs)
213 void free(
void *_o)
throw()
218 unsigned long addr = (
unsigned long)_o;
220 Slab_i *s = (Slab_i*)addr;
222 if (s->cache !=
this)
225 Free_o *o =
reinterpret_cast<Free_o*
>(_o);
230 bool was_full =
false;
277 s != _partial_slabs.
end(); ++s)
278 count += s->num_free;
295 template<
typename Type,
int Slab_size =
L4_PAGESIZE,
296 int Max_free = 2,
template<
typename A>
class Alloc =
New_allocator >
303 typedef Type Obj_type;
316 return (Type*)
Base_slab<
sizeof(Type), Slab_size,
317 Max_free, Alloc>::alloc();
346 template<
int Obj_size,
int Slab_size =
L4_PAGESIZE,
347 int Max_free = 2,
template<
typename A>
class Alloc =
New_allocator >
354 typedef void Obj_type;
365 void *
alloc() throw() {
return _a.alloc(); }
371 void free(
void *p)
throw() { _a.free(p); }
393 template<
int _O,
int _S,
int _M,
template<
typename A>
class Alloc >
413 template<
typename Type,
int Slab_size =
L4_PAGESIZE,
414 int Max_free = 2,
template<
typename A>
class Alloc =
New_allocator >
420 typedef Type Obj_type;
428 Max_free, Alloc>::alloc();
Type * alloc()
Allocate an object of type Type.
unsigned free_objects() const
Get the number of free objects in the slab allocator.
Helper type to distinguish the oeprator new version that does not throw exceptions.
Alloc< Slab_i > Slab_alloc
Type of the allocator for the slab caches.
Value_type front() const
Return the first element in the list.
Merged slab allocator (allocators for objects of the same size are merged together).
Slab allocator for object of type Type.
Merged slab allocator (allocators for objects of the same size are merged together).
#define L4_PAGESIZE
Minimal page size (in bytes).
void * alloc()
Allocate an object.
maximum number of free slab caches.
Basic element type for a double-linked H_list.
unsigned total_objects() const
Get the total number of objects managed by the slab allocator.
static void remove(T *e)
Remove the given element from its list.
void free(Type *o)
Free the object addressed by o.
Const_iterator end() const
Return a const iterator to the end of the list.
void free(void *p)
Free the given object (p).
unsigned total_objects() const
Get the total number of objects managed by the slab allocator.
Type * alloc()
Allocate an object of type Type.
void push_front(T *e)
Add element to the front of the list.
unsigned free_objects() const
Get the total number of objects managed by the slab allocator.
Iterator begin()
Return an iterator to the beginning of the list.
bool empty() const
Check if the list is empty.
Standard allocator based on operator new () .