--- deliantra/server/include/util.h 2006/12/16 03:08:26 1.17 +++ deliantra/server/include/util.h 2006/12/16 21:40:26 1.18 @@ -45,13 +45,22 @@ }; // strictly the same as g_slice_alloc, but never returns 0 -void *salloc (int size) throw (std::bad_alloc); +void *salloc (int size) throw (std::bad_alloc); // also copies src into the new area, like "memdup" -void *salloc (int size, void *src) throw (std::bad_alloc); +// if src is 0, clears the memory +void *salloc (int size, void *src) throw (std::bad_alloc); + +// and as a template +template +inline T *salloc (int size) throw (std::bad_alloc) { return (T *)salloc (size * sizeof (T)); } +template +inline T *salloc (int size, T *src) throw (std::bad_alloc) { return (T *)salloc (size * sizeof (T), (void *)src); } + // for symmetry -inline void sfree (void *ptr, int size) throw () +template +inline void sfree (T *ptr, int size) throw () { - g_slice_free1 (size, ptr); + g_slice_free1 (size * sizeof (T), (void *)ptr); } // a STL-compatible allocator that uses g_slice @@ -85,12 +94,12 @@ pointer allocate (size_type n, const_pointer = 0) { - return static_cast(salloc (n * sizeof (Tp))); + return salloc (n); } void deallocate (pointer p, size_type n) { - sfree (static_cast(p), n * sizeof (Tp)); + sfree (p, n); } size_type max_size ()const throw ()