NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1
23#ifndef MUTT_MUTT_MEMORY_H
24#define MUTT_MUTT_MEMORY_H
25
26#include <stddef.h>
27
28#undef MAX
29#undef MIN
30#undef CLAMP
31#define MAX(a, b) (((a) < (b)) ? (b) : (a))
32#define MIN(a, b) (((a) < (b)) ? (a) : (b))
33#define CLAMP(val, lo, hi) MIN(hi, MAX(lo, val))
34
35#undef ROUND_UP
36#define ROUND_UP(NUM, STEP) ((((NUM) + (STEP) -1) / (STEP)) * (STEP))
37
38#define mutt_array_size(x) (sizeof(x) / sizeof((x)[0]))
39
40#define MUTT_MEM_CALLOC(n, type) ((type *) mutt_mem_calloc(n, sizeof(type)))
41#define MUTT_MEM_MALLOC(n, type) ((type *) mutt_mem_mallocarray(n, sizeof(type)))
42
43#define MUTT_MEM_REALLOC(pptr, n, type) \
44( \
45 _Generic(*(pptr), type *: mutt_mem_reallocarray(pptr, n, sizeof(type))) \
46)
47
48void *mutt_mem_calloc(size_t nmemb, size_t size);
49void mutt_mem_free(void *ptr);
50void *mutt_mem_malloc(size_t size);
51void *mutt_mem_mallocarray(size_t nmemb, size_t size);
52void mutt_mem_realloc(void *pptr, size_t size);
53void mutt_mem_reallocarray(void *pptr, size_t nmemb, size_t size);
54
55#define FREE(x) mutt_mem_free(x)
56
57#endif /* MUTT_MUTT_MEMORY_H */
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:76
void * mutt_mem_mallocarray(size_t nmemb, size_t size)
Allocate memory on the heap (array version)
Definition: memory.c:129
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:146
void mutt_mem_free(void *ptr)
Release memory allocated on the heap.
Definition: memory.c:94
void mutt_mem_reallocarray(void *pptr, size_t nmemb, size_t size)
Resize a block of memory on the heap (array version)
Definition: memory.c:162
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:113