From c90d4af8750bef77ce9abe91df80d5d98ba297d7 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 29 Oct 2024 14:37:19 -0400 Subject: alloc: Don't require size % align == 0 Allowing unaligned sizes will allow us to allocate aligned slabs with additional metadata in the tail without ballooning the allocation size for large alignments. Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2244.htm#dr_460 Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2072.htm --- tests/alloc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/alloc.c') diff --git a/tests/alloc.c b/tests/alloc.c index f91b428..046613a 100644 --- a/tests/alloc.c +++ b/tests/alloc.c @@ -11,6 +11,14 @@ #include void check_alloc(void) { + // Check aligned allocation + void *ptr; + bfs_everify((ptr = zalloc(64, 129))); + bfs_check((uintptr_t)ptr % 64 == 0); + bfs_echeck((ptr = xrealloc(ptr, 64, 129, 65))); + bfs_check((uintptr_t)ptr % 64 == 0); + free(ptr); + // Check sizeof_flex() struct flexible { alignas(64) int foo[8]; -- cgit v1.2.3