ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.11 by root, Tue Sep 12 20:55:40 2006 UTC vs.
Revision 1.13 by root, Thu Sep 14 00:07:15 2006 UTC

39 { 39 {
40 g_slice_free1 (s, p); 40 g_slice_free1 (s, p);
41 } 41 }
42}; 42};
43 43
44void throw_bad_alloc () throw (std::bad_alloc); 44// strictly the same as g_slice_alloc, but never returns 0
45
46void *alloc (int s) throw (std::bad_alloc); 45void *alloc (int s) throw (std::bad_alloc);
46// for symmetry
47void dealloc (void *p, int s) throw (); 47inline 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
51template<typename Tp> 54template<typename Tp>
52struct slice_allocator 55struct 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines