/* application's main //*/ int main() { element_t* first = NULL; element_t* last = first; global_list_size = 0; // alloc puts("alloc"); alloclist((void*) &first, (void*) &last); printf("\n"); // output puts("elements - before"); printlist(first); printf("\n"); puts("sorting"); sort((void*) &first); printf("\n"); puts("elements - after"); printlist(first); printf("\n"); // free puts("free"); freelist((void*) &first); printf("\n"); // exit puts("READY."); exit(EXIT_SUCCESS); }
void test_typed_alloc(void) { char *tmp_gc; Managed mem_gc = (Managed) iMalloc(1 Mb, GCD + ASCENDING_SIZE); Priv_mem priv_mem_gc = style_to_priv((Memory) mem_gc); // Test allocating 10 pointers, 5 ints and 8 chars tmp_gc = mem_gc->gc.alloc((Memory) mem_gc, "10*5i8c"); CU_ASSERT(alloclist(priv_mem_gc) != NULL); CU_ASSERT(alloclist(priv_mem_gc)->size == 10 * sizeof(void*) + 5 * sizeof(int) + 8 * sizeof(char)); CU_ASSERT(freelist(priv_mem_gc) != NULL); CU_ASSERT(freelist(priv_mem_gc)->size == (1 Mb - (10 * sizeof(void*) + 5 * sizeof(int) + 8 * sizeof(char)))); free_lists(priv_mem_gc->lists); free(priv_mem_gc->as->start); free(priv_mem_gc); }
void test_alloclist(void) { Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE); Priv_mem new_mem = style_to_priv((Memory) mem); CU_ASSERT(alloclist(new_mem) == new_mem->lists->alloclist); free_lists(new_mem->lists); free(new_mem->as->start); free(new_mem); }
void test_managed_alloc(void) { char *tmp_rc; char *tmp_gc; char *tmp_rc2; char *tmp_gc2; Managed mem_rc = (Managed) iMalloc(1 Mb, REFCOUNT + ASCENDING_SIZE); Managed mem_gc = (Managed) iMalloc(1 Mb, GCD + ASCENDING_SIZE); Priv_mem priv_mem_rc = style_to_priv((Memory) mem_rc); Priv_mem priv_mem_gc = style_to_priv((Memory) mem_gc); // Test allocating 1 Kb tmp_rc = mem_rc->alloc((Memory) mem_rc, 1 Kb); CU_ASSERT(alloclist(priv_mem_rc) != NULL); CU_ASSERT(alloclist(priv_mem_rc)->size == 1 Kb); CU_ASSERT(freelist(priv_mem_rc) != NULL); CU_ASSERT(freelist(priv_mem_rc)->size == 1 Mb - 1 Kb); tmp_gc = mem_gc->alloc((Memory) mem_gc, 1 Kb); CU_ASSERT(alloclist(priv_mem_gc) != NULL); CU_ASSERT(alloclist(priv_mem_gc)->size == 1 Kb); CU_ASSERT(freelist(priv_mem_gc) != NULL); CU_ASSERT(freelist(priv_mem_gc)->size == 1 Mb - 1 Kb); // Allocate all remeaining space. tmp_rc = mem_rc->alloc((Memory) mem_rc, 1 Mb - 1 Kb); CU_ASSERT(alloclist(priv_mem_rc) != NULL); CU_ASSERT(alloclist(priv_mem_rc)->size == 1 Mb - 1 Kb); CU_ASSERT(freelist(priv_mem_rc) == NULL); tmp_gc = mem_gc->alloc((Memory) mem_gc, 1 Mb - 1 Kb); CU_ASSERT(alloclist(priv_mem_gc) != NULL); CU_ASSERT(alloclist(priv_mem_gc)->size == 1 Mb - 1 Kb); CU_ASSERT(freelist(priv_mem_gc) == NULL); // This allocation should fail using refcount, but succeed using gc. // Note: tmp no longer points to the 1 Kb block allocated in the beginning. tmp_rc2 = mem_rc->alloc((Memory) mem_rc, 1 Kb); CU_ASSERT(tmp_rc2 == NULL); zero_stack_above(); tmp_gc2 = mem_gc->alloc((Memory) mem_gc, 1 Kb); CU_ASSERT(tmp_gc2 != NULL); CU_ASSERT(alloclist(priv_mem_gc)->size == 1 Kb); CU_ASSERT(freelist(priv_mem_gc) == NULL); }