Skip to content

Commit be0226f

Browse files
committed
feat(mem-alloc): add aligned allocation API declaration
Add mem_allocator_malloc_aligned() API with support for both GC_VERIFY enabled and disabled modes. Related to DESIGN_ALIGNED_ALLOC.md
1 parent fcec30e commit be0226f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

core/shared/mem-alloc/mem_alloc.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,34 @@ mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size);
4646
void
4747
mem_allocator_free(mem_allocator_t allocator, void *ptr);
4848

49+
/* Aligned allocation support */
50+
#ifndef GC_MIN_ALIGNMENT
51+
#define GC_MIN_ALIGNMENT 8
52+
#endif
53+
54+
#if BH_ENABLE_GC_VERIFY == 0
55+
56+
void *
57+
mem_allocator_malloc_aligned(mem_allocator_t allocator, uint32_t size,
58+
uint32_t alignment);
59+
60+
#define mem_allocator_malloc_aligned_internal(allocator, size, alignment, \
61+
file, line) \
62+
mem_allocator_malloc_aligned(allocator, size, alignment)
63+
64+
#else /* BH_ENABLE_GC_VERIFY != 0 */
65+
66+
void *
67+
mem_allocator_malloc_aligned_internal(mem_allocator_t allocator,
68+
uint32_t size, uint32_t alignment,
69+
const char *file, int line);
70+
71+
#define mem_allocator_malloc_aligned(allocator, size, alignment) \
72+
mem_allocator_malloc_aligned_internal(allocator, size, alignment, \
73+
__FILE__, __LINE__)
74+
75+
#endif /* end of BH_ENABLE_GC_VERIFY */
76+
4977
int
5078
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
5179
uint32 pool_buf_size);

0 commit comments

Comments
 (0)