--- deliantra/server/include/util.h 2006/12/17 19:07:23 1.19 +++ deliantra/server/include/util.h 2006/12/17 23:10:35 1.20 @@ -44,23 +44,23 @@ } }; +void *salloc_ (int n) throw (std::bad_alloc); +void *salloc_ (int n, void *src) throw (std::bad_alloc); + // strictly the same as g_slice_alloc, but never returns 0 -void *salloc (int size) throw (std::bad_alloc); +template +inline T *salloc (int n = 1) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T)); } + // also copies src into the new area, like "memdup" // 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); } +inline T *salloc (int n, T *src) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), (void *)src); } // for symmetry template -inline void sfree (T *ptr, int size) throw () +inline void sfree (T *ptr, int n = 1) throw () { - g_slice_free1 (size * sizeof (T), (void *)ptr); + g_slice_free1 (n * sizeof (T), (void *)ptr); } // a STL-compatible allocator that uses g_slice