Memory management wrappers. More...
#include <stddef.h>
Go to the source code of this file.
Macros | |
#define | MAX(a, b) (((a) < (b)) ? (b) : (a)) |
#define | MIN(a, b) (((a) < (b)) ? (a) : (b)) |
#define | CLAMP(val, lo, hi) MIN(hi, MAX(lo, val)) |
#define | ROUND_UP(NUM, STEP) ((((NUM) + (STEP) -1) / (STEP)) * (STEP)) |
#define | mutt_array_size(x) (sizeof(x) / sizeof((x)[0])) |
#define | MUTT_MEM_CALLOC(n, type) ((type *) mutt_mem_calloc(n, sizeof(type))) |
#define | MUTT_MEM_MALLOC(n, type) ((type *) mutt_mem_mallocarray(n, sizeof(type))) |
#define | MUTT_MEM_REALLOC(pptr, n, type) |
#define | FREE(x) mutt_mem_free(x) |
Functions | |
void * | mutt_mem_calloc (size_t nmemb, size_t size) |
Allocate zeroed memory on the heap. | |
void | mutt_mem_free (void *ptr) |
Release memory allocated on the heap. | |
void * | mutt_mem_malloc (size_t size) |
Allocate memory on the heap. | |
void * | mutt_mem_mallocarray (size_t nmemb, size_t size) |
Allocate memory on the heap (array version) | |
void | mutt_mem_realloc (void *pptr, size_t size) |
Resize a block of memory on the heap. | |
void | mutt_mem_reallocarray (void *pptr, size_t nmemb, size_t size) |
Resize a block of memory on the heap (array version) | |
Memory management wrappers.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file memory.h.
#define ROUND_UP | ( | NUM, | |
STEP | |||
) | ((((NUM) + (STEP) -1) / (STEP)) * (STEP)) |
#define MUTT_MEM_CALLOC | ( | n, | |
type | |||
) | ((type *) mutt_mem_calloc(n, sizeof(type))) |
#define MUTT_MEM_MALLOC | ( | n, | |
type | |||
) | ((type *) mutt_mem_mallocarray(n, sizeof(type))) |
#define MUTT_MEM_REALLOC | ( | pptr, | |
n, | |||
type | |||
) |
#define FREE | ( | x | ) | mutt_mem_free(x) |
void * mutt_mem_calloc | ( | size_t | nmemb, |
size_t | size | ||
) |
Allocate zeroed memory on the heap.
nmemb | Number of blocks |
size | Size of blocks |
ptr | Memory on the heap |
The caller should call mutt_mem_free() to release the memory
Definition at line 77 of file memory.c.
void mutt_mem_free | ( | void * | ptr | ) |
void * mutt_mem_malloc | ( | size_t | size | ) |
Allocate memory on the heap.
size | Size of block to allocate |
ptr | Memory on the heap |
The caller should call mutt_mem_free() to release the memory
Definition at line 114 of file memory.c.
void * mutt_mem_mallocarray | ( | size_t | nmemb, |
size_t | size | ||
) |
Allocate memory on the heap (array version)
nmemb | Number of blocks |
size | Size of blocks |
ptr | Memory on the heap |
The caller should call mutt_mem_free() to release the memory
Definition at line 130 of file memory.c.
void mutt_mem_realloc | ( | void * | pptr, |
size_t | size | ||
) |
Resize a block of memory on the heap.
pptr | Address of pointer to memory block to resize |
size | New size |
If the new size is zero, the block will be freed.
Definition at line 147 of file memory.c.
void mutt_mem_reallocarray | ( | void * | pptr, |
size_t | nmemb, | ||
size_t | size | ||
) |
Resize a block of memory on the heap (array version)
pptr | Address of pointer to memory block to resize |
nmemb | Number of blocks |
size | Size of blocks |
If the new size is zero, the block will be freed.
Definition at line 163 of file memory.c.