… | |
… | |
39 | { |
39 | { |
40 | g_slice_free1 (s, p); |
40 | g_slice_free1 (s, p); |
41 | } |
41 | } |
42 | }; |
42 | }; |
43 | |
43 | |
44 | void throw_bad_alloc () throw (std::bad_alloc); |
44 | // strictly the same as g_slice_alloc, but never returns 0 |
45 | |
|
|
46 | void *alloc (int s) throw (std::bad_alloc); |
45 | void *alloc (int s) throw (std::bad_alloc); |
|
|
46 | // for symmetry |
47 | void dealloc (void *p, int s) throw (); |
47 | inline void dealloc (void *p, int s) throw () |
|
|
48 | { |
|
|
49 | g_slice_free1 (s, p); |
|
|
50 | } |
48 | |
51 | |
49 | // a STL-compatible allocator that uses g_slice |
52 | // a STL-compatible allocator that uses g_slice |
50 | // boy, this is verbose |
53 | // boy, this is verbose |
51 | template<typename Tp> |
54 | template<typename Tp> |
52 | struct slice_allocator |
55 | struct slice_allocator |
… | |
… | |
80 | return static_cast<pointer>(alloc (n * sizeof (Tp))); |
83 | return static_cast<pointer>(alloc (n * sizeof (Tp))); |
81 | } |
84 | } |
82 | |
85 | |
83 | void deallocate (pointer p, size_type n) |
86 | void deallocate (pointer p, size_type n) |
84 | { |
87 | { |
85 | dealloc (static_cast<void *>(p), n); |
88 | dealloc (static_cast<void *>(p), n * sizeof (Tp)); |
86 | } |
89 | } |
87 | |
90 | |
88 | size_type max_size ()const throw () |
91 | size_type max_size ()const throw () |
89 | { |
92 | { |
90 | return size_t (-1) / sizeof (Tp); |
93 | return size_t (-1) / sizeof (Tp); |