Thanks to visit codestin.com
Credit goes to code.neomutt.org

NeoMutt  2025-12-11-189-gceedb6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1
23
24#ifndef MUTT_MUTT_MEMORY_H
25#define MUTT_MUTT_MEMORY_H
26
27#if defined __has_include
28# if __has_include(<stdcountof.h>)
29# include <stdcountof.h>
30# endif
31#endif
32#include <stddef.h>
33
34#undef MAX
35#undef MIN
36#undef CLAMP
37#define MAX(a, b) (((a) < (b)) ? (b) : (a))
38#define MIN(a, b) (((a) < (b)) ? (a) : (b))
39#define CLAMP(val, lo, hi) MIN(hi, MAX(lo, val))
40
41#undef ROUND_UP
42#define ROUND_UP(NUM, STEP) ((((NUM) + (STEP) -1) / (STEP)) * (STEP))
43
44#if !defined(countof)
45# define countof(x) (sizeof(x) / sizeof((x)[0]))
46#endif
47
48#define MUTT_MEM_CALLOC(n, type) ((type *) mutt_mem_calloc(n, sizeof(type)))
49#define MUTT_MEM_MALLOC(n, type) ((type *) mutt_mem_mallocarray(n, sizeof(type)))
50
51#define MUTT_MEM_REALLOC(pptr, n, type) \
52( \
53 _Generic(*(pptr), type *: mutt_mem_reallocarray(pptr, n, sizeof(type))) \
54)
55
56void *mutt_mem_calloc(size_t nmemb, size_t size);
57void mutt_mem_free(void *ptr);
58void *mutt_mem_malloc(size_t size);
59void *mutt_mem_mallocarray(size_t nmemb, size_t size);
60void mutt_mem_realloc(void *pptr, size_t size);
61void mutt_mem_reallocarray(void *pptr, size_t nmemb, size_t size);
62
63#define FREE(x) mutt_mem_free(x)
64
65#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