예제 #1
0
파일: test.c 프로젝트: pipul/gogo
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;
}
예제 #2
0
파일: edpnet.c 프로젝트: konghan/edp.io
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);
}