… | |
… | |
42 | { |
42 | { |
43 | g_slice_free1 (s, p); |
43 | g_slice_free1 (s, p); |
44 | } |
44 | } |
45 | }; |
45 | }; |
46 | |
46 | |
|
|
47 | void *salloc_ (int n) throw (std::bad_alloc); |
|
|
48 | void *salloc_ (int n, void *src) throw (std::bad_alloc); |
|
|
49 | |
47 | // strictly the same as g_slice_alloc, but never returns 0 |
50 | // strictly the same as g_slice_alloc, but never returns 0 |
48 | void *alloc (int s) throw (std::bad_alloc); |
51 | template<typename T> |
|
|
52 | inline T *salloc (int n = 1) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T)); } |
|
|
53 | |
|
|
54 | // also copies src into the new area, like "memdup" |
|
|
55 | // if src is 0, clears the memory |
|
|
56 | template<typename T> |
|
|
57 | inline T *salloc (int n, T *src) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), (void *)src); } |
|
|
58 | |
49 | // for symmetry |
59 | // for symmetry |
50 | inline void dealloc (void *p, int s) throw () |
60 | template<typename T> |
|
|
61 | inline void sfree (T *ptr, int n = 1) throw () |
51 | { |
62 | { |
52 | g_slice_free1 (s, p); |
63 | g_slice_free1 (n * sizeof (T), (void *)ptr); |
53 | } |
64 | } |
54 | |
65 | |
55 | // a STL-compatible allocator that uses g_slice |
66 | // a STL-compatible allocator that uses g_slice |
56 | // boy, this is verbose |
67 | // boy, this is verbose |
57 | template<typename Tp> |
68 | template<typename Tp> |
… | |
… | |
81 | pointer address (reference x) const { return &x; } |
92 | pointer address (reference x) const { return &x; } |
82 | const_pointer address (const_reference x) const { return &x; } |
93 | const_pointer address (const_reference x) const { return &x; } |
83 | |
94 | |
84 | pointer allocate (size_type n, const_pointer = 0) |
95 | pointer allocate (size_type n, const_pointer = 0) |
85 | { |
96 | { |
86 | return static_cast<pointer>(alloc (n * sizeof (Tp))); |
97 | return salloc<Tp> (n); |
87 | } |
98 | } |
88 | |
99 | |
89 | void deallocate (pointer p, size_type n) |
100 | void deallocate (pointer p, size_type n) |
90 | { |
101 | { |
91 | dealloc (static_cast<void *>(p), n * sizeof (Tp)); |
102 | sfree<Tp> (p, n); |
92 | } |
103 | } |
93 | |
104 | |
94 | size_type max_size ()const throw () |
105 | size_type max_size ()const throw () |
95 | { |
106 | { |
96 | return size_t (-1) / sizeof (Tp); |
107 | return size_t (-1) / sizeof (Tp); |
… | |
… | |
222 | inline void assign (char (&dst)[N], const char *src) |
233 | inline void assign (char (&dst)[N], const char *src) |
223 | { |
234 | { |
224 | assign ((char *)&dst, src, N); |
235 | assign ((char *)&dst, src, N); |
225 | } |
236 | } |
226 | |
237 | |
|
|
238 | typedef double tstamp; |
|
|
239 | |
|
|
240 | // return current time as timestampe |
|
|
241 | tstamp now (); |
|
|
242 | |
227 | #endif |
243 | #endif |
228 | |
244 | |