| 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 |
template <class U> |
| 16 |
bool operator == (const slice_allocator<U> &) noexcept { return true ; } |
| 17 |
template <class U> |
| 18 |
bool operator != (const slice_allocator<U> &) noexcept { return false; } |
| 19 |
|
| 20 |
Tp *allocate (std::size_t n) |
| 21 |
{ |
| 22 |
return (Tp *)g_slice_alloc (n * sizeof (Tp)); |
| 23 |
} |
| 24 |
|
| 25 |
void deallocate (Tp *p, std::size_t n) noexcept |
| 26 |
{ |
| 27 |
g_slice_free1 (n * sizeof (Tp), p); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
#endif |