SAF
|
Contiguous memory allocation functions for multi-dimensional arrays. More...
Go to the source code of this file.
Macros | |
#define | FLATTEN2D(A) (*A) /* || (&A[0][0]) */ |
Use this macro when passing a 2-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data. | |
#define | FLATTEN3D(A) (**A) /* || (&A[0][0][0]) */ |
Use this macro when passing a 3-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data. | |
#define | FLATTEN4D(A) (***A) /* || (&A[0][0][0][0]) */ |
Use this macro when passing a 4-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data. | |
#define | FLATTEN5D(A) (****A) /* || (&A[0][0][0][0][0]) */ |
Use this macro when passing a 5-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data. | |
#define | FLATTEN6D(A) (*****A) /* || (&A[0][0][0][0][0][0]) */ |
Use this macro when passing a 6-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data. | |
Functions | |
void * | malloc1d (size_t dim1_data_size) |
1-D malloc (same as malloc, but with error checking) | |
void * | calloc1d (size_t dim1, size_t data_size) |
1-D calloc (same as calloc, but with error checking) | |
void * | realloc1d (void *ptr, size_t dim1_data_size) |
1-D realloc (same as realloc, but with error checking) | |
void ** | malloc2d (size_t dim1, size_t dim2, size_t data_size) |
2-D malloc (contiguously allocated, so use free() as usual to deallocate) | |
void ** | calloc2d (size_t dim1, size_t dim2, size_t data_size) |
2-D calloc (contiguously allocated, so use free() as usual to deallocate) | |
void ** | realloc2d (void **ptr, size_t dim1, size_t dim2, size_t data_size) |
2-D realloc which does NOT retain previous data order | |
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 | |
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) | |
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) | |
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 | |
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 | |
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) | |
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) | |
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 | |
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) | |
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) | |
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 | |
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) | |
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) | |
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 | |
Contiguous memory allocation functions for multi-dimensional arrays.
Adapted from: https://github.com/leomccormack/md_malloc
An example of allocating, indexing and freeing a 3-D "array":
Definition in file md_malloc.h.
#define FLATTEN2D | ( | A | ) | (*A) /* || (&A[0][0]) */ |
Use this macro when passing a 2-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data.
e.g.
Definition at line 65 of file md_malloc.h.
#define FLATTEN3D | ( | A | ) | (**A) /* || (&A[0][0][0]) */ |
Use this macro when passing a 3-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data.
Definition at line 72 of file md_malloc.h.
#define FLATTEN4D | ( | A | ) | (***A) /* || (&A[0][0][0][0]) */ |
Use this macro when passing a 4-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data.
Definition at line 79 of file md_malloc.h.
#define FLATTEN5D | ( | A | ) | (****A) /* || (&A[0][0][0][0][0]) */ |
Use this macro when passing a 5-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data.
Definition at line 86 of file md_malloc.h.
#define FLATTEN6D | ( | A | ) | (*****A) /* || (&A[0][0][0][0][0][0]) */ |
Use this macro when passing a 6-D dynamic multi-dimensional array to memset, memcpy or any other function that expects a flat contiguous 1-D block of data.
Definition at line 93 of file md_malloc.h.
void * calloc1d | ( | size_t | dim1, |
size_t | data_size ) |
1-D calloc (same as calloc, but with error checking)
Definition at line 69 of file md_malloc.c.
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 at line 102 of file md_malloc.c.
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 at line 170 of file md_malloc.c.
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 at line 264 of file md_malloc.c.
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 at line 349 of file md_malloc.c.
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 at line 460 of file md_malloc.c.
void * malloc1d | ( | size_t | dim1_data_size | ) |
1-D malloc (same as malloc, but with error checking)
Definition at line 59 of file md_malloc.c.
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 at line 89 of file md_malloc.c.
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 at line 151 of file md_malloc.c.
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 at line 238 of file md_malloc.c.
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 at line 315 of file md_malloc.c.
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 at line 416 of file md_malloc.c.
void * realloc1d | ( | void * | ptr, |
size_t | dim1_data_size ) |
1-D realloc (same as realloc, but with error checking)
Definition at line 79 of file md_malloc.c.
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 at line 115 of file md_malloc.c.
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 at line 127 of file md_malloc.c.
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 at line 189 of file md_malloc.c.
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 at line 207 of file md_malloc.c.
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 at line 290 of file md_malloc.c.
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 at line 383 of file md_malloc.c.
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 at line 504 of file md_malloc.c.