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.70 by root, Sun Apr 20 05:24:55 2008 UTC vs.
Revision 1.75 by root, Tue May 6 16:55:26 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify 6 * Deliantra is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or 8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
20 */ 20 */
21 21
22#ifndef UTIL_H__ 22#ifndef UTIL_H__
23#define UTIL_H__ 23#define UTIL_H__
24 24
25#define DEBUG_POISON 0xaa // poison memory before freeing it if != 0 25#define DEBUG_POISON 0x00 // poison memory before freeing it if != 0
26#define DEBUG_SALLOC 0 // add a debug wrapper around all sallocs 26#define DEBUG_SALLOC 0 // add a debug wrapper around all sallocs
27#define PREFER_MALLOC 0 // use malloc and not the slice allocator 27#define PREFER_MALLOC 0 // use malloc and not the slice allocator
28 28
29#if __GNUC__ >= 3 29#if __GNUC__ >= 3
30# define is_constant(c) __builtin_constant_p (c) 30# define is_constant(c) __builtin_constant_p (c)
224 g_slice_free1 (n * sizeof (T), (void *)ptr); 224 g_slice_free1 (n * sizeof (T), (void *)ptr);
225 assert (slice_alloc >= 0);//D 225 assert (slice_alloc >= 0);//D
226 } 226 }
227} 227}
228 228
229// nulls the pointer
230template<typename T>
231inline void sfree0 (T *&ptr, int n = 1) throw ()
232{
233 sfree<T> (ptr, n);
234 ptr = 0;
235}
236
229// makes dynamically allocated objects zero-initialised 237// makes dynamically allocated objects zero-initialised
230struct zero_initialised 238struct zero_initialised
231{ 239{
232 void *operator new (size_t s, void *p) 240 void *operator new (size_t s, void *p)
233 { 241 {
241 } 249 }
242 250
243 void *operator new[] (size_t s) 251 void *operator new[] (size_t s)
244 { 252 {
245 return salloc0<char> (s); 253 return salloc0<char> (s);
254 }
255
256 void operator delete (void *p, size_t s)
257 {
258 sfree ((char *)p, s);
259 }
260
261 void operator delete[] (void *p, size_t s)
262 {
263 sfree ((char *)p, s);
264 }
265};
266
267// makes dynamically allocated objects zero-initialised
268struct slice_allocated
269{
270 void *operator new (size_t s, void *p)
271 {
272 return p;
273 }
274
275 void *operator new (size_t s)
276 {
277 return salloc<char> (s);
278 }
279
280 void *operator new[] (size_t s)
281 {
282 return salloc<char> (s);
246 } 283 }
247 284
248 void operator delete (void *p, size_t s) 285 void operator delete (void *p, size_t s)
249 { 286 {
250 sfree ((char *)p, s); 287 sfree ((char *)p, s);
356 int get_range (int r_min, int r_max); 393 int get_range (int r_min, int r_max);
357}; 394};
358 395
359typedef tausworthe_random_generator rand_gen; 396typedef tausworthe_random_generator rand_gen;
360 397
361extern rand_gen rndm; 398extern rand_gen rndm, rmg_rndm;
362 399
363INTERFACE_CLASS (attachable) 400INTERFACE_CLASS (attachable)
364struct refcnt_base 401struct refcnt_base
365{ 402{
366 typedef int refcnt_t; 403 typedef int refcnt_t;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines