From: Gabriel Corona Date: Thu, 10 Apr 2014 14:05:36 +0000 (+0200) Subject: [mc] Avoid allocation/deallocation in init_heap_information X-Git-Tag: v3_11~120^2^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/202ba7a673cd667e6f91a0ef03a28f47ef508be7?hp=12aaf9a3876a50383a653c57d38506eb97917176 [mc] Avoid allocation/deallocation in init_heap_information --- diff --git a/src/xbt/mmalloc/mm_diff.c b/src/xbt/mmalloc/mm_diff.c index 6ad7ec640f..af5bd8853e 100644 --- a/src/xbt/mmalloc/mm_diff.c +++ b/src/xbt/mmalloc/mm_diff.c @@ -315,6 +315,10 @@ static int equal_fragments(struct s_mm_diff *state, int b1, int f1, int b2, int int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, xbt_dynar_t i2){ if(mm_diff_info==NULL) { mm_diff_info = xbt_new0(struct s_mm_diff, 1); + mm_diff_info->equals_to1 = NULL; + mm_diff_info->equals_to2 = NULL; + mm_diff_info->types1 = NULL; + mm_diff_info->types2 = NULL; } struct s_mm_diff *state = mm_diff_info; @@ -338,12 +342,18 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, state->to_ignore1 = i1; state-> to_ignore2 = i2; - state->equals_to1 = calloc(state->heaplimit * MAX_FRAGMENT_PER_BLOCK, sizeof(s_heap_area_t)); - state->types1 = calloc(state->heaplimit * MAX_FRAGMENT_PER_BLOCK, sizeof(type_name *)); - state->equals_to2 = calloc(state->heaplimit * MAX_FRAGMENT_PER_BLOCK, sizeof(s_heap_area_t)); - state->types2 = calloc(state->heaplimit * MAX_FRAGMENT_PER_BLOCK, sizeof(type_name *)); + if(state->heaplimit > state->available) { + state->equals_to1 = realloc(state->equals_to1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + state->types1 = realloc(state->types1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + state->equals_to2 = realloc(state->equals_to2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + state->types2 = realloc(state->types2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + state->available = state->heaplimit; + } - state->available = state->heaplimit; + memset(state->equals_to1, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + memset(state->equals_to2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + memset(state->types1, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + memset(state->types2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); if(MC_is_active()){ MC_ignore_global_variable("mm_diff_info"); @@ -355,20 +365,6 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, void reset_heap_information(){ - struct s_mm_diff *state = mm_diff_info; - - free(state->equals_to1); - free(state->equals_to2); - free(state->types1); - free(state->types2); - - state->s_heap = NULL, state->heapbase1 = NULL, state->heapbase2 = NULL; - state->heapinfo1 = NULL, state->heapinfo2 = NULL; - state->heaplimit = 0, state->heapsize1 = 0, state->heapsize2 = 0; - state->to_ignore1 = NULL, state->to_ignore2 = NULL; - state->equals_to1 = NULL, state->equals_to2 = NULL; - state->types1 = NULL, state->types2 = NULL; - } int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_mheap_t heap1, xbt_mheap_t heap2){