From 855cbd04a9698112d1a8894e6802d0f5e95a0881 Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Sat, 5 Jul 2025 11:40:16 -0500 Subject: [PATCH] Added memory size defines --- include/mem.h | 4 ++++ tests/01_alloc.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/mem.h b/include/mem.h index d1ec329..4bafece 100644 --- a/include/mem.h +++ b/include/mem.h @@ -7,6 +7,10 @@ #define SIZEOF(x) (ptrdiff_t)sizeof(x) #define NELEMS(a) (sizeof(a) / sizeof(*(a))) #define LEN(s) (NELEMS(s) - 1) +#define KB(x) ((size_t)(x) << 10) // 1 KB = 1024 bytes +#define MB(x) ((size_t)(x) << 20) // 1 MB = 1024 * 1024 bytes +#define GB(x) ((size_t)(x) << 30) // 1 GB = 1024 * 1024 * 1024 bytes + extern const Exception out_of_memory; // OOM Exception extern void *mem_alloc (size_t nbytes,const char *file, int line); diff --git a/tests/01_alloc.c b/tests/01_alloc.c index 302c28d..61f64ce 100644 --- a/tests/01_alloc.c +++ b/tests/01_alloc.c @@ -20,7 +20,7 @@ static bool isZeroed(void *memory, unsigned int size) int main(void){ - char *buf = ALLOC(BUFSZ); + char *buf = ALLOC(MB(20)); ASSERTED(buf != NULL); ASSERTED(isZeroed(buf, BUFSZ) == false); FREE(buf);