title: Pointers pointing contiguous memory
body: <p>Consider the following code</p>
  
  <pre><code>struct foo
  {
      const int txt_len;
      const int num_len;
  
      char * txt;
      int * num;
  
      foo(int tl, int nl): txt_len(tl), num_len(nl)
      {
          char * tmp = new char[txt_len * sizeof(char) + num_len * sizeof(int)];
  
          txt = new (tmp) char [txt_len * sizeof(char)];
          num = new (tmp + txt_len * sizeof(char)) int[num_len * sizeof(int)];
  
          // is this the same as above?
          // txt = tmp;                                  
          // num = (int *) (tmp + txt_len * sizeof(char));
      }
  
      ~foo()
      {
          delete[] txt; // is this the right way to free the memory?
      }
  };
  </code></pre>
  
  <p>I want <code>*txt</code> and <code>*num</code> to be contiguous, is that the best way to do it?</p>
  
  <p>also is there any difference between placement new and pointer arithmetic? which one should I use?</p>