memory.h
Go to the documentation of this file.
1 /*!**********************************************************************
2 *
3 * @copyright Copyright (C) 2016 Siemens Aktiengesellschaft.\n
4 * All rights reserved.
5 *
6 *************************************************************************
7 *
8 * @file memory.h
9 * @date Jul 28, 2016
10 * @brief Memory module header file.
11 *
12 * This module contains functions and macro definitions for memory allocation/deallocation operations.
13 *
14 ************************************************************************/
15 
16 #ifndef MEMORY_H_
17 #define MEMORY_H_
18 
19 #include "mcl/mcl_common.h"
20 
29 void *memory_allocate(mcl_size_t bytes, const char *function, unsigned line);
30 
40 void *memory_allocate_with_zero(mcl_size_t count, mcl_size_t bytes, const char *function, unsigned line);
41 
51 void *memory_reallocate(void *p, mcl_size_t bytes, const char *function, unsigned line);
52 
60 void memory_release(void *p, const char *function, unsigned line);
61 
70 void *memory_malloc(mcl_size_t size);
71 
81 void *memory_calloc(mcl_size_t count, mcl_size_t bytes);
82 
92 void *memory_realloc(void *p, mcl_size_t bytes);
93 
101 void memory_free(void *p);
102 
103 /*
104  * Usage examples for memory macros :
105  * char *buf = MCL_MALLOC(100);
106  *
107  * --
108  *
109  * struct demo_t demo;
110  * MCL_NEW(demo);
111  *
112  * --
113  *
114  * buf = MCL_RESIZE(buf, new_size);
115  *
116  * --
117  *
118  * MCL_FREE(demo);
119  */
120 #define MCL_MALLOC(bytes) memory_allocate(bytes, __FUNCTION__, __LINE__)
121 #define MCL_NEW(p) ((p) = MCL_MALLOC((long)sizeof (*p)))
122 #define MCL_CALLOC(count, bytes) memory_allocate_with_zero(count, bytes, __FUNCTION__, __LINE__)
123 #define MCL_NEW_WITH_ZERO(p) ((p) = MCL_CALLOC(1, (long)sizeof *(p)))
124 #define MCL_RESIZE(p, bytes) ((p) = memory_reallocate(p, bytes, __FUNCTION__, __LINE__))
125 #define MCL_FREE(p) ((void)(memory_release((p), __FUNCTION__, (mcl_uint32_t)__LINE__), (p) = MCL_NULL))
126 
127 #endif //MCL_MEMORY_H_
void * memory_malloc(mcl_size_t size)
malloc wrapper
Definition: memory.c:99
Common module interface header file.
void * memory_allocate(mcl_size_t bytes, const char *function, unsigned line)
Definition: memory.c:22
void * memory_reallocate(void *p, mcl_size_t bytes, const char *function, unsigned line)
Definition: memory.c:57
void memory_release(void *p, const char *function, unsigned line)
Definition: memory.c:83
size_t mcl_size_t
Definition: mcl_common.h:38
void * memory_allocate_with_zero(mcl_size_t count, mcl_size_t bytes, const char *function, unsigned line)
Definition: memory.c:39
void memory_free(void *p)
free wrapper
Definition: memory.c:129
void * memory_calloc(mcl_size_t count, mcl_size_t bytes)
calloc wrapper
Definition: memory.c:109
void * memory_realloc(void *p, mcl_size_t bytes)
realloc wrapper
Definition: memory.c:119