--- deliantra/server/include/util.h 2008/04/20 05:24:55 1.70 +++ deliantra/server/include/util.h 2008/05/06 16:55:26 1.75 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * * Deliantra is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #ifndef UTIL_H__ #define UTIL_H__ -#define DEBUG_POISON 0xaa // poison memory before freeing it if != 0 +#define DEBUG_POISON 0x00 // poison memory before freeing it if != 0 #define DEBUG_SALLOC 0 // add a debug wrapper around all sallocs #define PREFER_MALLOC 0 // use malloc and not the slice allocator @@ -226,6 +226,14 @@ } } +// nulls the pointer +template +inline void sfree0 (T *&ptr, int n = 1) throw () +{ + sfree (ptr, n); + ptr = 0; +} + // makes dynamically allocated objects zero-initialised struct zero_initialised { @@ -256,6 +264,35 @@ } }; +// makes dynamically allocated objects zero-initialised +struct slice_allocated +{ + void *operator new (size_t s, void *p) + { + return p; + } + + void *operator new (size_t s) + { + return salloc (s); + } + + void *operator new[] (size_t s) + { + return salloc (s); + } + + void operator delete (void *p, size_t s) + { + sfree ((char *)p, s); + } + + void operator delete[] (void *p, size_t s) + { + sfree ((char *)p, s); + } +}; + // a STL-compatible allocator that uses g_slice // boy, this is verbose template @@ -358,7 +395,7 @@ typedef tausworthe_random_generator rand_gen; -extern rand_gen rndm; +extern rand_gen rndm, rmg_rndm; INTERFACE_CLASS (attachable) struct refcnt_base