1 #ifndef __WILC_MEMORY_H__
2 #define __WILC_MEMORY_H__
6 * @brief Memory OS wrapper functionality
8 * @sa wilc_oswrapper.h top level OS wrapper file
14 * @struct tstrWILC_MemoryAttrs
15 * @brief Memory API options
21 } tstrWILC_MemoryAttrs
;
24 * @brief Allocates a given size of bytes
25 * @param[in] u32Size size of memory in bytes to be allocated
26 * @param[in] strAttrs Optional attributes, NULL for default
27 * if not NULL, pAllocationPool should point to the pool to use for
28 * this allocation. if NULL memory will be allocated directly from
30 * @param[in] pcFileName file name of the calling code for debugging
31 * @param[in] u32LineNo line number of the calling code for debugging
32 * @return The new allocated block, NULL if allocation fails
33 * @note It is recommended to use of of the wrapper macros instead of
34 * calling this function directly
35 * @sa sttrWILC_MemoryAttrs
44 void *WILC_MemoryAlloc(u32 u32Size
, tstrWILC_MemoryAttrs
*strAttrs
,
45 WILC_Char
*pcFileName
, u32 u32LineNo
);
48 * @brief Allocates a given size of bytes and zero filling it
49 * @param[in] u32Size size of memory in bytes to be allocated
50 * @param[in] strAttrs Optional attributes, NULL for default
51 * if not NULL, pAllocationPool should point to the pool to use for
52 * this allocation. if NULL memory will be allocated directly from
54 * @param[in] pcFileName file name of the calling code for debugging
55 * @param[in] u32LineNo line number of the calling code for debugging
56 * @return The new allocated block, NULL if allocation fails
57 * @note It is recommended to use of of the wrapper macros instead of
58 * calling this function directly
59 * @sa sttrWILC_MemoryAttrs
68 void *WILC_MemoryCalloc(u32 u32Size
, tstrWILC_MemoryAttrs
*strAttrs
,
69 WILC_Char
*pcFileName
, u32 u32LineNo
);
72 * @brief Reallocates a given block to a new size
73 * @param[in] pvOldBlock the old memory block, if NULL then this function
74 * behaves as a new allocation function
75 * @param[in] u32NewSize size of the new memory block in bytes, if zero then
76 * this function behaves as a free function
77 * @param[in] strAttrs Optional attributes, NULL for default
78 * if pAllocationPool!=NULL and pvOldBlock==NULL, pAllocationPool
79 * should point to the pool to use for this allocation.
80 * if pAllocationPool==NULL and pvOldBlock==NULL memory will be
81 * allocated directly from the system
82 * if and pvOldBlock!=NULL, pAllocationPool will not be inspected
83 * and reallocation is done from the same pool as the original block
84 * @param[in] pcFileName file name of the calling code for debugging
85 * @param[in] u32LineNo line number of the calling code for debugging
86 * @return The new allocated block, possibly same as pvOldBlock
87 * @note It is recommended to use of of the wrapper macros instead of
88 * calling this function directly
89 * @sa sttrWILC_MemoryAttrs
96 void *WILC_MemoryRealloc(void *pvOldBlock
, u32 u32NewSize
,
97 tstrWILC_MemoryAttrs
*strAttrs
, WILC_Char
*pcFileName
, u32 u32LineNo
);
100 * @brief Frees given block
101 * @param[in] pvBlock the memory block to be freed
102 * @param[in] strAttrs Optional attributes, NULL for default
103 * @param[in] pcFileName file name of the calling code for debugging
104 * @param[in] u32LineNo line number of the calling code for debugging
105 * @note It is recommended to use of of the wrapper macros instead of
106 * calling this function directly
107 * @sa sttrWILC_MemoryAttrs
110 * @sa WILC_FREE_SET_NULL
111 * @sa WILC_FREE_IF_TRUE
116 void WILC_MemoryFree(const void *pvBlock
, tstrWILC_MemoryAttrs
*strAttrs
,
117 WILC_Char
*pcFileName
, u32 u32LineNo
);
120 * @brief standrad malloc wrapper with custom attributes
122 #define WILC_MALLOC_EX(__size__, __attrs__) \
124 (__size__), __attrs__, NULL, 0))
127 * @brief standrad calloc wrapper with custom attributes
129 #define WILC_CALLOC_EX(__size__, __attrs__) \
130 (WILC_MemoryCalloc( \
131 (__size__), __attrs__, NULL, 0))
134 * @brief standrad realloc wrapper with custom attributes
136 #define WILC_REALLOC_EX(__ptr__, __new_size__, __attrs__) \
137 (WILC_MemoryRealloc( \
138 (__ptr__), (__new_size__), __attrs__, NULL, 0))
140 * @brief standrad free wrapper with custom attributes
142 #define WILC_FREE_EX(__ptr__, __attrs__) \
144 (__ptr__), __attrs__, NULL, 0))
147 * @brief Allocates a block (with custom attributes) of given type and number of
150 #define WILC_NEW_EX(__struct_type__, __n_structs__, __attrs__) \
151 ((__struct_type__ *)WILC_MALLOC_EX( \
152 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
155 * @brief Allocates a block (with custom attributes) of given type and number of
156 * elements and Zero-fills it
158 #define WILC_NEW_0_EX(__struct_type__, __n_structs__, __attrs__) \
159 ((__struct_type__ *)WILC_CALLOC_EX( \
160 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
163 * @brief Frees a block (with custom attributes), also setting the original pointer
166 #define WILC_FREE_SET_NULL_EX(__ptr__, __attrs__) do { \
167 if (__ptr__ != NULL) { \
168 WILC_FREE_EX(__ptr__, __attrs__); \
174 * @brief Frees a block (with custom attributes) if the pointer expression evaluates
177 #define WILC_FREE_IF_TRUE_EX(__ptr__, __attrs__) do { \
178 if (__ptr__ != NULL) { \
179 WILC_FREE_EX(__ptr__, __attrs__); \
184 * @brief standrad malloc wrapper with default attributes
186 #define WILC_MALLOC(__size__) \
187 WILC_MALLOC_EX(__size__, NULL)
190 * @brief standrad calloc wrapper with default attributes
192 #define WILC_CALLOC(__size__) \
193 WILC_CALLOC_EX(__size__, NULL)
196 * @brief standrad realloc wrapper with default attributes
198 #define WILC_REALLOC(__ptr__, __new_size__) \
199 WILC_REALLOC_EX(__ptr__, __new_size__, NULL)
202 * @brief standrad free wrapper with default attributes
204 #define WILC_FREE(__ptr__) \
205 WILC_FREE_EX(__ptr__, NULL)
208 * @brief Allocates a block (with default attributes) of given type and number of
211 #define WILC_NEW(__struct_type__, __n_structs__) \
212 WILC_NEW_EX(__struct_type__, __n_structs__, NULL)
215 * @brief Allocates a block (with default attributes) of given type and number of
216 * elements and Zero-fills it
218 #define WILC_NEW_0(__struct_type__, __n_structs__) \
219 WILC_NEW_O_EX(__struct_type__, __n_structs__, NULL)
222 * @brief Frees a block (with default attributes), also setting the original pointer
225 #define WILC_FREE_SET_NULL(__ptr__) \
226 WILC_FREE_SET_NULL_EX(__ptr__, NULL)
229 * @brief Frees a block (with default attributes) if the pointer expression evaluates
232 #define WILC_FREE_IF_TRUE(__ptr__) \
233 WILC_FREE_IF_TRUE_EX(__ptr__, NULL)
This page took 0.040896 seconds and 5 git commands to generate.