23#ifndef MUTT_MUTT_MEMORY_H
24#define MUTT_MUTT_MEMORY_H
26#if defined __has_include
27# if __has_include(<stdcountof.h>)
28# include <stdcountof.h>
36#define MAX(a, b) (((a) < (b)) ? (b) : (a))
37#define MIN(a, b) (((a) < (b)) ? (a) : (b))
38#define CLAMP(val, lo, hi) MIN(hi, MAX(lo, val))
41#define ROUND_UP(NUM, STEP) ((((NUM) + (STEP) -1) / (STEP)) * (STEP))
44# define countof(x) (sizeof(x) / sizeof((x)[0]))
47#define MUTT_MEM_CALLOC(n, type) ((type *) mutt_mem_calloc(n, sizeof(type)))
48#define MUTT_MEM_MALLOC(n, type) ((type *) mutt_mem_mallocarray(n, sizeof(type)))
50#define MUTT_MEM_REALLOC(pptr, n, type) \
52 _Generic(*(pptr), type *: mutt_mem_reallocarray(pptr, n, sizeof(type))) \
62#define FREE(x) mutt_mem_free(x)
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed 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_free(void *ptr)
Release memory allocated 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)
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.