--- deliantra/server/include/util.h 2006/09/12 20:55:40 1.11 +++ deliantra/server/include/util.h 2006/09/16 13:11:20 1.15 @@ -11,6 +11,9 @@ #include +// use a gcc extension for auto declarations until ISO C++ sanctifies them +#define AUTODECL(var,expr) typeof(expr) var = (expr) + // makes dynamically allocated objects zero-initialised struct zero_initialised { @@ -41,10 +44,13 @@ } }; -void throw_bad_alloc () throw (std::bad_alloc); - +// strictly the same as g_slice_alloc, but never returns 0 void *alloc (int s) throw (std::bad_alloc); -void dealloc (void *p, int s) throw (); +// for symmetry +inline void dealloc (void *p, int s) throw () +{ + g_slice_free1 (s, p); +} // a STL-compatible allocator that uses g_slice // boy, this is verbose @@ -82,7 +88,7 @@ void deallocate (pointer p, size_type n) { - dealloc (static_cast(p), n); + dealloc (static_cast(p), n * sizeof (Tp)); } size_type max_size ()const throw () @@ -106,8 +112,7 @@ mutable int refcnt; refcounted () : refcnt (0) { } void refcnt_inc () { ++refcnt; } - void refcnt_dec () { --refcnt; - if (refcnt < 0)abort();}//D + void refcnt_dec () { --refcnt; } }; template