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