FAR void *mm_calloc(FAR struct mm_heap_s *heap, size_t n, size_t elem_size) { FAR void *ret = NULL; if (n > 0 && elem_size > 0) { ret = mm_zalloc(heap, n * elem_size); } return ret; }
struct dyay *dyay_new(struct ymd_mach *vm, int max) { struct dyay *x = NULL; if (max <= 0) max = 0; x = gc_new(vm, sizeof(*x), T_DYAY); x->count = 0; x->max = max; if (x->max > 0) x->elem = mm_zalloc(vm, x->max, sizeof(*x->elem)); return x; }
static struct kstr *kstr_new(struct ymd_mach *vm, int raw, const char *z, int count) { struct kstr *x = NULL; if (count < 0) count = strlen(z); if (raw) { x = mm_zalloc(vm, 1, sizeof(*x) + count); x->type = T_KSTR; x->marked = GC_GRAY_BIT0; } else x = gc_new(vm, sizeof(*x) + count, T_KSTR); x->len = count; if (!z) memset(x->land, 0, count + 1); else memcpy(x->land, z, count); return x; }
FAR void *zalloc(size_t size) { #ifdef CONFIG_ARCH_ADDRENV /* Use malloc() because it implements the sbrk() logic */ FAR void *alloc = malloc(size); if (alloc) { memset(alloc, 0, size); } return alloc; #else /* Use mm_zalloc() becuase it implements the clear */ return mm_zalloc(USR_HEAP, size); #endif }
void *user_zalloc(size_t size) { void *buf = mm_zalloc(&g_mmheap_user, size); assert_param(buf); return buf; }
FAR void *kmm_zalloc(size_t size) { return mm_zalloc(&g_kmmheap, size); }