title: Segmentation fault when I call operator new in linux mint
body: <p>On Linux Mint, I use operator <code>new</code> to alloc memory:</p>
  
  <pre><code>int maxNummber = 1000000;
  int* arr = new int[maxNumber];
  </code></pre>
  
  <p>when I run my code, I meet </p>
  
  <pre><code>flybird@flybird ~/cplusplus_study $ ./a.out 
  -412179
  Segmentation fault
  </code></pre>
  
  <p>when I change <code>maxNumber = 100</code>, the code runs successfully.</p>
  
  <p>the result of command <code>free -m</code>:</p>
  
  <pre><code>flybird@flybird ~/cplusplus_study $ free -m
                total       used       free     shared    buffers     cached
  Mem:          2016        800       1216          0        158        359
  -/+ buffers/cache:        283       1733
  Swap:         2045          0       2045
  </code></pre>
  
  <hr>
  
  <p><a href="https://github.com/wangyangkobe/cplusplus_study/blob/master/BitMap.cpp" rel="nofollow">This</a> is the actual code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;ctime&gt;
  #include &lt;memory&gt;
  #include &lt;string.h&gt;
  #include &lt;iterator&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  class GenRandomNumber;
  
  class BitMap
  {
  public:
      BitMap(int n):maxNumer(n)
      {
          int length = 1 + n / BITSPERWORD;
          pData = new int[length];
          memset(pData, 0, length);
      }
      void set(int i)
      {
          pData[i&gt;&gt;SHIFT] |= 1&lt;&lt;(i &amp; MASK); // i&amp;MASK 相当于i%32
      }
      void clear(int i)
      {
          pData[i&gt;&gt;SHIFT] &amp;= ~(1&lt;&lt;(i &amp; MASK)); // i&gt;&gt;SHIFT 相当于 i/32
      }
      bool test(int i)
      {
          return pData[i&gt;&gt;SHIFT] &amp; (1&lt;&lt;(i &amp; MASK));
      }
  
      void sort(string inputFile, string outputFile)
      {
          ifstream read(inputFile.c_str());
          ofstream write(outputFile.c_str());
          int temp = 0;
  
          while (read&gt;&gt;temp)
              set(temp);
  
          for (int i = 0; i &lt; maxNumer; ++i)
          {
              if(test(i))
                  write&lt;&lt;i&lt;&lt;endl;
          }
          read.close();
          write.close();
      }
      ~BitMap()
      {
          delete []pData;
          pData = NULL;
      }
  private:
      int* pData;
      int maxNumer;
      enum{ SHIFT = 5, MASK = 0x1F, BITSPERWORD = 32};
  };
  
  class GenRandomNumber
  {
  public:
      static GenRandomNumber* genInstance()
      {
          if(!mInstance.get())
              mInstance.reset(new GenRandomNumber());
          return mInstance.get();
      }
  
      void generate1(string fileName, int m, int maxNumber)
      {
          ofstream outFile(fileName.c_str());
          int* arr = new int[maxNumber];
          for(int i = 0; i &lt; maxNumber; i++)
              arr[i] = i;
  
          int temp = 0;
          for(int j = 0; j &lt; m; j++)
          {
              temp = randomRange(j, maxNumber - 1);
              cout&lt;&lt;temp&lt;&lt;endl;
              swap(arr[j], arr[temp]);
          }
  
          copy(arr, arr + m, ostream_iterator&lt;int&gt;(outFile, "\n"));
          delete []arr;
          outFile.close();
      }
  
      void generate2(string fileName, int m, int maxNumber)
      {
          BitMap bitmap(maxNumber);
          ofstream outFile(fileName.c_str());
          int count = 0;
          int temp;
          while (count &lt; m)
          {
              srand(time(NULL));
              temp = randomRange(0, maxNumber);
              cout&lt;&lt;temp&lt;&lt;endl;
              if (!bitmap.test(temp))
              {
                  bitmap.set(temp);
                  outFile&lt;&lt;temp&lt;&lt;endl;
                  count++;
              }
          }
          outFile.close();
      }
  private:
      GenRandomNumber(){};
      GenRandomNumber(const GenRandomNumber&amp;);
      GenRandomNumber&amp; operator=(const GenRandomNumber&amp;);
  
      int randomRange(int low, int high)
      {
          srand(clock()); // better than srand(time(NULL))
          return low + (RAND_MAX * rand() + rand()) % (high + 1 - low);;
      }
  
      static auto_ptr&lt;GenRandomNumber&gt; mInstance;
  };
  auto_ptr&lt;GenRandomNumber&gt; GenRandomNumber::mInstance;
  
  
  
  int main()
  {
      const int MAX_NUMBER = 1000000;
      GenRandomNumber *pGen = GenRandomNumber::genInstance();
      pGen-&gt;generate1("test.txt", MAX_NUMBER, MAX_NUMBER);
      BitMap bitmap(MAX_NUMBER);
      bitmap.sort("test.txt", "sort.txt");
      return 0;
  }
  </code></pre>