!------------------------------------------------------------------------------- ! alloc.inf - A test of dynmem.h ! written by John 'katre' Cater ! katre@ruf.rice.edu !------------------------------------------------------------------------------- Constant DYNMEM_DEBUG 2; Include "dynmem.h"; Constant VAR_SIZE 1200; Array var_array -> VAR_SIZE; Constant FIX_SIZE 320; Array fix_array -> FIX_SIZE; MemController var_mem with mem_array var_array, array_size VAR_SIZE, ! gc_percent 1, ; MemController fix_mem with mem_array fix_array, array_size FIX_SIZE, block_size 32, ! gc_percent 1, ; [Main; print "Testing variable length allocation.^"; var_check(); print "^"; print "Testing fixed length allocation.^"; fix_check(); ]; [var_check ptr; var_mem.check_mem(); var_mem.profile(); print "About to allocate...^"; ptr = var_mem.alloc_ptr(12); print "Done.^"; var_mem.check_mem(); print "About to reallocate...^"; ptr = var_mem.realloc_ptr(ptr, 120); var_mem.check_mem(); ptr = var_mem.realloc_ptr(ptr, 20); print "Done.^"; var_mem.check_mem(); print "About to fake freeing...^"; fix_mem.free_ptr(ptr); print "Done.^"; print "About to free...^"; var_mem.free_ptr(ptr); print "Done.^"; var_mem.check_mem(); print "Collecting freed memory...^"; var_mem.force_collect(); print "Done.^"; var_mem.check_mem(); ]; [fix_check ptr ptr2 ptr3; fix_mem.check_mem(); fix_mem.profile(); print "About to allocate...^"; ptr = fix_mem.alloc_ptr(); print "Done.^"; fix_mem.check_mem(); print "About to reallocate...^"; fix_mem.realloc_ptr(ptr, 120); print "Done.^"; ptr2 = fix_mem.alloc_ptr(); ptr3 = fix_mem.alloc_ptr(); fix_mem.check_mem(); print "About to free...^"; fix_mem.free_ptr(ptr); fix_mem.free_ptr(ptr2); fix_mem.free_ptr(ptr3); print "Done.^"; fix_mem.check_mem(); print "Collecting freed memory...^"; fix_mem.force_collect(); print "Done.^"; fix_mem.check_mem(); ];