Ejemplo n.º 1
0
Archivo: test.c Proyecto: 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;
}
Ejemplo n.º 2
0
maxHeap*	mheap_create()
{
	maxHeap* res = (maxHeap*) calloc(1,sizeof(maxHeap));
	if (!res) {
		fprintf(stderr,"Error allocating heap struct\n");
		return NULL;
	}
	if (!mheap_init(res))
		return NULL;
	return res;
}