|
| 1 | +/*** |
| 2 | + * libccd |
| 3 | + * --------------------------------- |
| 4 | + * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz> |
| 5 | + * |
| 6 | + * |
| 7 | + * This file is part of libccd. |
| 8 | + * |
| 9 | + * Distributed under the OSI-approved BSD License (the "License"); |
| 10 | + * see accompanying file BDS-LICENSE for details or see |
| 11 | + * <http://www.opensource.org/licenses/bsd-license.php>. |
| 12 | + * |
| 13 | + * This software is distributed WITHOUT ANY WARRANTY; without even the |
| 14 | + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | + * See the License for more information. |
| 16 | + */ |
| 17 | + |
| 18 | +#ifndef __CCD_ALLOC_H__ |
| 19 | +#define __CCD_ALLOC_H__ |
| 20 | + |
| 21 | +#include <stdlib.h> |
| 22 | + |
| 23 | +#ifdef __cplusplus |
| 24 | +extern "C" { |
| 25 | +#endif /* __cplusplus */ |
| 26 | + |
| 27 | +/** |
| 28 | + * Functions and macros required for memory allocation. |
| 29 | + */ |
| 30 | + |
| 31 | +/* Memory allocation: */ |
| 32 | +#define __CCD_ALLOC_MEMORY(type, ptr_old, size) \ |
| 33 | + (type *)realloc((void *)ptr_old, (size)) |
| 34 | + |
| 35 | +/** Allocate memory for one element of type. */ |
| 36 | +#define CCD_ALLOC(type) \ |
| 37 | + __CCD_ALLOC_MEMORY(type, NULL, sizeof(type)) |
| 38 | + |
| 39 | +/** Allocate memory for array of elements of type type. */ |
| 40 | +#define CCD_ALLOC_ARR(type, num_elements) \ |
| 41 | + __CCD_ALLOC_MEMORY(type, NULL, sizeof(type) * (num_elements)) |
| 42 | + |
| 43 | +#define CCD_REALLOC_ARR(ptr, type, num_elements) \ |
| 44 | + __CCD_ALLOC_MEMORY(type, ptr, sizeof(type) * (num_elements)) |
| 45 | + |
| 46 | +#ifdef __cplusplus |
| 47 | +} /* extern "C" */ |
| 48 | +#endif /* __cplusplus */ |
| 49 | + |
| 50 | +#endif /* __CCD_ALLOC_H__ */ |
0 commit comments