Esempio n. 1
0
File: test.c Progetto: 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;
}
Esempio n. 2
0
static inline edp_event_t * edpnet_alloc_event(){
    edpnet_data_t   *ed = &__edpnet_data;

    if(!ed->ed_init)
	return NULL;

    return (edp_event_t *)mcache_alloc(ed->ed_evcache);
}