void test_mem(void *args) { struct mcache *mc; int i, size; void *ptr; void **memmap; mheap_init(&runtime_mheap, myalloc, myfree); mc = mheap_mcache_create(&runtime_mheap); memmap = malloc(sizeof(void *) * max_small_size); if (!memmap) BUG_ON(); memset(memmap, 0, sizeof(void *) * max_small_size); for (size = 1; size <= max_small_size; size++) { ptr = mcache_alloc(mc, size, 1); if (!ptr) { printf("-ENOMEM of %d\n", size); break; } printf("malloc: %ld %d\n", ptr, size); memmap[size - 1] = ptr; } for (size -= 1; size; size--) { mcache_free(mc, memmap[size - 1], size); } free(memmap); mheap_mcache_destroy(&runtime_mheap, mc); mheap_exit(&runtime_mheap); if (myallocn != myfreen) { fprintf(stdout, "%d alloc, %d free\n", myallocn, myfreen); BUG_ON(); } return; }
static inline void edpnet_free_event(edp_event_t *ev){ edpnet_data_t *ed = &__edpnet_data; ASSERT(ed->ed_init); mcache_free(ed->ed_evcache, ev); }