From c874b9402315dc2e4d57093a36d0effed1c18ca4 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Mon, 24 Apr 2006 14:04:21 +0000 Subject: 2006-04-24 Akira TAGOH * hieroglyph/hgallocator-bfit.c (_hg_bfit_block_new): store a heap id. (_hg_allocator_bfit_get_free_block): update the amount of the used heap in pool. (_hg_allocator_bfit_relocate): new function. (_hg_allocator_bfit_real_free): update the amount of the used heap in pool. (_hg_allocator_bfit_real_resize): implemented. --- tests/hgmem.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/hgmem.c b/tests/hgmem.c index 0b2594c..345202b 100644 --- a/tests/hgmem.c +++ b/tests/hgmem.c @@ -1,16 +1,17 @@ #include #include #include +#include #include int -main(void) +test_ffit(void) { HgAllocator *allocator; HgMemPool *pool; gchar *s, *s2; - hg_mem_init(); + g_print("ffit\n"); allocator = hg_allocator_new(hg_allocator_ffit_get_vtable()); pool = hg_mem_pool_new(allocator, "test", 256, TRUE); if (pool == NULL) { @@ -35,6 +36,55 @@ main(void) hg_mem_free(s); hg_mem_pool_destroy(pool); hg_allocator_destroy(allocator); + + return 0; +} + +int +test_bfit(void) +{ + HgAllocator *allocator; + HgMemPool *pool; + gchar *s, *s2; + + allocator = hg_allocator_new(hg_allocator_bfit_get_vtable()); + pool = hg_mem_pool_new(allocator, "test", 256, TRUE); + if (pool == NULL) { + g_print("Failed to create a pool.\n"); + return 1; + } + s = hg_mem_alloc(pool, 16); + printf("%p\n", s); + s2 = hg_mem_alloc(pool, 256); + printf("%p:%p\n", s, s2); + if (s == NULL || s2 == NULL) { + g_print("Failed to alloc a memory: %p %p.\n", s, s2); + return 1; + } + strcpy(s, "test"); + strcpy(s2, "test"); + if (strcmp(s, s2)) { + g_print("Failed to compare the memory.\n"); + return 1; + } + hg_mem_free(s2); + hg_mem_free(s); + hg_mem_pool_destroy(pool); + hg_allocator_destroy(allocator); + + return 0; +} + +int +main(void) +{ + hg_mem_init(); + + if (test_ffit() != 0) + return 1; + if (test_bfit() != 0) + return 1; + hg_mem_finalize(); return 0; -- cgit v1.2.3