title: Boehm GC++ garbage collector : Too many heap sections Increase MAXHINCR or MAX_HEAP_SECTS
body: <p>I am using the Boehm C++ Garbage collector in an application. The application uses the Levenshtein Deterministic Finite Automata Python program to calculate the Levenshtein distance between two string. I have ported the Python program to C++ on version of Centos Linux using gcc 4.1.2.</p>
  
  <p>Recently, I noticed that after I run the application more than 10 minutes, I get the SIGABRT error message: <code>Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS</code>. I was wondering if anyone knew how to fix or work around this problem. </p>
  
  <p>Here is my gdb stack trace. Thank you.</p>
  
  <pre><code>  Program received signal SIGABRT, Aborted.
  (gdb) bt
  #0  0x002ed402 in __kernel_vsyscall ()
  #1  0x00b1bdf0 in raise () from /lib/libc.so.6
  #2  0x00b1d701 in abort () from /lib/libc.so.6
  #3  0x00e28db4 in GC_abort (msg=0xf36de0 "Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS")
      at ../Source/misc.c:1079
  #4  0x00e249a0 in GC_add_to_heap (p=0xb7cb7000, bytes=65536) at ../Source/alloc.c:812
  #5  0x00e24e45 in GC_expand_hp_inner (n=16) at ../Source/alloc.c:966
  #6  0x00e24fc5 in GC_collect_or_expand (needed_blocks=1, ignore_off_page=0) at ../Source/alloc.c:1032
  #7  0x00e2519a in GC_allocobj (sz=6, kind=1) at ../Source/alloc.c:1087
  #8  0x00e31e90 in GC_generic_malloc_inner (lb=20, k=1) at ../Source/malloc.c:138
  #9  0x00e31fde in GC_generic_malloc (lb=20, k=1) at ../Source/malloc.c:194
  #10 0x00e322b8 in GC_malloc (lb=20) at ../Source/malloc.c:319
  #11 0x00df5ab5 in gc::operator new (size=20) at ../Include/gc_cpp.h:275
  #12 0x00de7cb7 in __automata_combined_test2__::DFA::levenshtein_automata (this=0xb7b49080, term=0xb7cb5d20, k=1) 
  at ../Source/automata_combined_test2.cpp:199
  #13 0x00e3a085 in cDedupe::AccurateNearCompare (this=0x8052cd8, 
      Str1_=0x81f1a1d "GEMMA     OSTRANDER GEM 10   
  DICARLO", ' ' &lt;repeats 13 times&gt;, "01748SUE       WOLFE     SUE 268  POND", ' ' &lt;repeats 16 times&gt;, 
  "01748REGINA    SHAKIN    REGI16   JAMIE", ' ' &lt;repeats 15 times&gt;, "01748KATHLEEN  MAZUR     CATH10   JAMIE    "
  ..., 
      Str2_=0x81f2917 "LINDA     ROBISON   LIN 53   CHESTNUT", ' ' &lt;repeats 12 times&gt;, 
  "01748MICHELLE  LITAVIS   MICH15   BLUEBERRY", ' ' &lt;repeats 11 times&gt;, "01748JOAN      TITUS     JO  6    SMITH", 
  ' ' &lt;repeats 15 times&gt;, "01748MELINDA   MCDOWELL  MEL 24   SMITH    "..., Size_=10, 
  </code></pre>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>I looked at Boehm Garbage Collector source and header files and realized that the: <code>Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS</code> error message could be fixed by adding &#8209;DLARGE_CONFIG to the CFLAGS section in my GNUmakefile.</p>
  
  <p>I tested this change to my GNUmakfile and found that the <code>Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS</code> error message no longer occuured. However I am getting a new segmentation fault (core dump). Using gdb I found that the GDB segmentation fault occured in the following function at line 20 (which I have annotated):</p>
  
  <pre><code>set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt; *NFA::next_state(set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt; *states, str *input) {
      tuple2&lt;__ss_int, __ss_int&gt; *state;
      set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt;::for_in_loop __3;
      set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt; *__0, *dest_states;
      dict&lt;str *, set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt; *&gt; *state_transitions;
      __iter&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt; *__1;
      __ss_int __2;
  
      dest_states = (new set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt;());
  
      FOR_IN_NEW(state,states,0,2,3)
          state_transitions = (this-&gt;transitions)-&gt;get(state, ((dict&lt;str *, set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt; *&gt; *)((new dict&lt;void *, void *&gt;()))));
  
      dest_states-&gt;update(state_transitions-&gt;get(input, new set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt;()));
      dest_states-&gt;update(state_transitions-&gt;get(NFA::ANY, new set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt;()));
      END_FOR
  
      return (new set&lt;tuple2&lt;__ss_int, __ss_int&gt; *&gt;(this-&gt;_expand(dest_states),1));//line20  
  }
  </code></pre>
  
  <p>I was wondering if it was possible to modify this function to fix the segmentation fault. Thank you.</p>