… | |
… | |
43 | g_slice_free1 (s, p); |
43 | g_slice_free1 (s, p); |
44 | } |
44 | } |
45 | }; |
45 | }; |
46 | |
46 | |
47 | // strictly the same as g_slice_alloc, but never returns 0 |
47 | // strictly the same as g_slice_alloc, but never returns 0 |
48 | void *alloc (int s) throw (std::bad_alloc); |
48 | void *salloc (int size) throw (std::bad_alloc); |
|
|
49 | // also copies src into the new area, like "memdup" |
|
|
50 | void *salloc (int size, void *src) throw (std::bad_alloc); |
49 | // for symmetry |
51 | // for symmetry |
50 | inline void dealloc (void *p, int s) throw () |
52 | inline void sfree (void *ptr, int size) throw () |
51 | { |
53 | { |
52 | g_slice_free1 (s, p); |
54 | g_slice_free1 (size, ptr); |
53 | } |
55 | } |
54 | |
56 | |
55 | // a STL-compatible allocator that uses g_slice |
57 | // a STL-compatible allocator that uses g_slice |
56 | // boy, this is verbose |
58 | // boy, this is verbose |
57 | template<typename Tp> |
59 | template<typename Tp> |
… | |
… | |
81 | pointer address (reference x) const { return &x; } |
83 | pointer address (reference x) const { return &x; } |
82 | const_pointer address (const_reference x) const { return &x; } |
84 | const_pointer address (const_reference x) const { return &x; } |
83 | |
85 | |
84 | pointer allocate (size_type n, const_pointer = 0) |
86 | pointer allocate (size_type n, const_pointer = 0) |
85 | { |
87 | { |
86 | return static_cast<pointer>(alloc (n * sizeof (Tp))); |
88 | return static_cast<pointer>(salloc (n * sizeof (Tp))); |
87 | } |
89 | } |
88 | |
90 | |
89 | void deallocate (pointer p, size_type n) |
91 | void deallocate (pointer p, size_type n) |
90 | { |
92 | { |
91 | dealloc (static_cast<void *>(p), n * sizeof (Tp)); |
93 | sfree (static_cast<void *>(p), n * sizeof (Tp)); |
92 | } |
94 | } |
93 | |
95 | |
94 | size_type max_size ()const throw () |
96 | size_type max_size ()const throw () |
95 | { |
97 | { |
96 | return size_t (-1) / sizeof (Tp); |
98 | return size_t (-1) / sizeof (Tp); |
… | |
… | |
222 | inline void assign (char (&dst)[N], const char *src) |
224 | inline void assign (char (&dst)[N], const char *src) |
223 | { |
225 | { |
224 | assign ((char *)&dst, src, N); |
226 | assign ((char *)&dst, src, N); |
225 | } |
227 | } |
226 | |
228 | |
|
|
229 | typedef double tstamp; |
|
|
230 | |
|
|
231 | // return current time as timestampe |
|
|
232 | tstamp now (); |
|
|
233 | |
227 | #endif |
234 | #endif |
228 | |
235 | |