1 /*
2  * Copyright (c) 1997 - 2001 Hansj�rg Malthaner
3  *
4  * This file is part of the Simutrans project under the artistic license.
5  * (see license.txt)
6  */
7 #ifndef SIMMEM_H
8 #define SIMMEM_H
9 
10 #include <stddef.h>
11 
12 void guarded_free(void* ptr);
13 
14 void* xmalloc(size_t size);             // Throws std::bad_alloc on failure
15 void* xrealloc(void * const ptr, size_t size); // Throws std::bad_alloc on failure
16 
17 #define MALLOC(type)             ((type*)xmalloc(sizeof(type)))       // Allocate an object of a certain type
18 #define MALLOCN(type, n)         ((type*)xmalloc(sizeof(type) * (n))) // Allocate n objects of a certain type
19 #define MALLOCF(type, member, n) ((type*)xmalloc(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
20 
21 #define REALLOC(ptr, type, n) (type*)xrealloc((void *)ptr, sizeof(type) * (n)) // Reallocate n objects of a certain type
22 
23 #endif
24