1 |
#ifndef SALLOC_H |
2 |
#define SALLOC_H |
3 |
|
4 |
// a C++ allocator trait class based on the slice allocator |
5 |
template<typename Tp> |
6 |
struct slice_allocator |
7 |
{ |
8 |
typedef Tp value_type; |
9 |
|
10 |
slice_allocator () noexcept { } |
11 |
template<typename Tp2> |
12 |
slice_allocator (const slice_allocator<Tp2> &) noexcept { } |
13 |
~slice_allocator () noexcept { } |
14 |
|
15 |
Tp *allocate (std::size_t n) |
16 |
{ |
17 |
return (Tp *)g_slice_alloc (n * sizeof (Tp)); |
18 |
} |
19 |
|
20 |
void deallocate (Tp *p, std::size_t n) noexcept |
21 |
{ |
22 |
g_slice_free1 (n * sizeof (Tp), p); |
23 |
} |
24 |
}; |
25 |
|
26 |
template <class T, class U> |
27 |
bool operator == (const slice_allocator<T>&, const slice_allocator<U>&) noexcept { return true ; } |
28 |
template <class T, class U> |
29 |
bool operator != (const slice_allocator<T>&, const slice_allocator<U>&) noexcept { return false; } |
30 |
|
31 |
#endif |