SAF
Loading...
Searching...
No Matches
md_malloc.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019 Leo McCormack
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22
45#ifndef MD_MALLOC_INCLUDED
46#define MD_MALLOC_INCLUDED
47
48#ifdef __cplusplus
49extern "C" {
50#endif /* __cplusplus */
51
65#define FLATTEN2D(A) (*A) /* || (&A[0][0]) */
66
72#define FLATTEN3D(A) (**A) /* || (&A[0][0][0]) */
73
79#define FLATTEN4D(A) (***A) /* || (&A[0][0][0][0]) */
80
86#define FLATTEN5D(A) (****A) /* || (&A[0][0][0][0][0]) */
87
93#define FLATTEN6D(A) (*****A) /* || (&A[0][0][0][0][0][0]) */
94
96void* malloc1d(size_t dim1_data_size);
97
99void* calloc1d(size_t dim1, size_t data_size);
100
102void* realloc1d(void* ptr, size_t dim1_data_size);
103
105void** malloc2d(size_t dim1, size_t dim2, size_t data_size);
106
108void** calloc2d(size_t dim1, size_t dim2, size_t data_size);
109
111void** realloc2d(void** ptr, size_t dim1, size_t dim2, size_t data_size);
112
118void** realloc2d_r(void** ptr, size_t new_dim1, size_t new_dim2,
119 size_t prev_dim1, size_t prev_dim2, size_t data_size);
120
122void*** malloc3d(size_t dim1, size_t dim2, size_t dim3, size_t data_size);
123
125void*** calloc3d(size_t dim1, size_t dim2, size_t dim3, size_t data_size);
126
128void*** realloc3d(void*** ptr, size_t dim1, size_t dim2, size_t dim3,
129 size_t data_size);
130
132void*** realloc3d_r(void*** ptr, size_t new_dim1, size_t new_dim2,
133 size_t new_dim3, size_t prev_dim1, size_t prev_dim2,
134 size_t prev_dim3, size_t data_size);
135
137void**** malloc4d(size_t dim1, size_t dim2, size_t dim3, size_t dim4,
138 size_t data_size);
139
141void**** calloc4d(size_t dim1, size_t dim2, size_t dim3, size_t dim4,
142 size_t data_size);
143
145void**** realloc4d(void**** ptr, size_t dim1, size_t dim2, size_t dim3,
146 size_t dim4, size_t data_size);
147
149void***** malloc5d(size_t dim1, size_t dim2, size_t dim3, size_t dim4,
150 size_t dim5, size_t data_size);
151
153void***** calloc5d(size_t dim1, size_t dim2, size_t dim3, size_t dim4,
154 size_t dim5, size_t data_size);
155
157void***** realloc5d(void***** ptr, size_t dim1, size_t dim2, size_t dim3,
158 size_t dim4, size_t dim5, size_t data_size);
159
161void****** malloc6d(size_t dim1, size_t dim2, size_t dim3, size_t dim4,
162 size_t dim5, size_t dim6, size_t data_size);
163
165void****** calloc6d(size_t dim1, size_t dim2, size_t dim3, size_t dim4,
166 size_t dim5, size_t dim6, size_t data_size);
167
169void****** realloc6d(void****** ptr, size_t dim1, size_t dim2, size_t dim3,
170 size_t dim4, size_t dim5, size_t dim6, size_t data_size);
171
172
173#ifdef __cplusplus
174} /*extern "C"*/
175#endif /* __cplusplus */
176
177#endif /* MD_MALLOC_INCLUDED */
void ** malloc2d(size_t dim1, size_t dim2, size_t data_size)
2-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:89
void **** realloc4d(void ****ptr, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t data_size)
4-D realloc which does NOT retain previous data order
Definition md_malloc.c:290
void ** realloc2d(void **ptr, size_t dim1, size_t dim2, size_t data_size)
2-D realloc which does NOT retain previous data order
Definition md_malloc.c:115
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
Definition md_malloc.c:59
void ****** malloc6d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t data_size)
6-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:416
void * calloc1d(size_t dim1, size_t data_size)
1-D calloc (same as calloc, but with error checking)
Definition md_malloc.c:69
void ****** realloc6d(void ******ptr, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t data_size)
6-D realloc which does NOT retain previous data order
Definition md_malloc.c:504
void * realloc1d(void *ptr, size_t dim1_data_size)
1-D realloc (same as realloc, but with error checking)
Definition md_malloc.c:79
void ***** realloc5d(void *****ptr, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t data_size)
5-D realloc which does NOT retain previous data order
Definition md_malloc.c:383
void *** malloc3d(size_t dim1, size_t dim2, size_t dim3, size_t data_size)
3-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:151
void *** realloc3d_r(void ***ptr, size_t new_dim1, size_t new_dim2, size_t new_dim3, size_t prev_dim1, size_t prev_dim2, size_t prev_dim3, size_t data_size)
3-D realloc which does retain previous data order
Definition md_malloc.c:207
void **** malloc4d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t data_size)
4-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:238
void **** calloc4d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t data_size)
4-D calloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:264
void ***** calloc5d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t data_size)
5-D calloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:349
void *** realloc3d(void ***ptr, size_t dim1, size_t dim2, size_t dim3, size_t data_size)
3-D realloc which does NOT retain previous data order
Definition md_malloc.c:189
void ** realloc2d_r(void **ptr, size_t new_dim1, size_t new_dim2, size_t prev_dim1, size_t prev_dim2, size_t data_size)
2-D realloc which does retain previous data order
Definition md_malloc.c:127
void ** calloc2d(size_t dim1, size_t dim2, size_t data_size)
2-D calloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:102
void ***** malloc5d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t data_size)
5-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:315
void *** calloc3d(size_t dim1, size_t dim2, size_t dim3, size_t data_size)
3-D calloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:170
void ****** calloc6d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t data_size)
6-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:460