From 17b480b3f207f90802d2e490b8da9d3019fa52c3 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Thu, 21 May 2009 12:47:11 +0200 Subject: [PATCH] Only allocate the safety region when max_heap_size = 0 --- src/c/alloc_2.d | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/c/alloc_2.d b/src/c/alloc_2.d index 20af46e76..29f2017bf 100644 --- a/src/c/alloc_2.d +++ b/src/c/alloc_2.d @@ -39,6 +39,13 @@ _ecl_set_max_heap_size(cl_index new_size) const cl_env_ptr the_env = ecl_process_env(); ecl_disable_interrupts_env(the_env); GC_set_max_heap_size(cl_core.max_heap_size = new_size); + if (new_size == 0) { + cl_index size = ecl_get_option(ECL_OPT_HEAP_SAFETY_AREA); + cl_core.safety_region = ecl_alloc_atomic_unprotected(size); + } else if (cl_core.safety_region) { + GC_FREE(cl_core.safety_region); + cl_core.safety_region = 0; + } ecl_enable_interrupts_env(the_env); } @@ -85,7 +92,7 @@ out_of_memory(size_t requested_bytes) * not reached them. */ if (cl_core.safety_region) { /* We can free some memory and try handling the error */ - GC_free(cl_core.safety_region); + GC_FREE(cl_core.safety_region); the_env->string_pool = Cnil; cl_core.safety_region = 0; method = 0; @@ -349,6 +356,13 @@ init_alloc(void) GC_clear_roots(); GC_disable(); GC_set_max_heap_size(cl_core.max_heap_size = ecl_get_option(ECL_OPT_HEAP_SIZE)); + /* Save some memory for the case we get tight. */ + if (cl_core.max_heap_size == 0) { + cl_index size = ecl_get_option(ECL_OPT_HEAP_SAFETY_AREA); + cl_core.safety_region = ecl_alloc_atomic_unprotected(size); + } else if (cl_core.safety_region) { + cl_core.safety_region = 0; + } #define init_tm(x,y,z) type_size[x] = (z) for (i = 0; i < t_end; i++) { @@ -398,9 +412,6 @@ init_alloc(void) init_tm(t_longfloat, "LONG-FLOAT", sizeof(struct ecl_long_float)); #endif - /* Save some memory for the case we get tight. */ - cl_core.safety_region = ecl_alloc_atomic(sizeof(cl_fixnum)*1024); - old_GC_push_other_roots = GC_push_other_roots; GC_push_other_roots = stacks_scanner; GC_start_call_back = (void (*)())finalize_queued;