title: c++ dynamic allocation (pixel map)
body: <p>im new to both (memory allocation and classes)</p>
  
  <p>im trying to make pixel map of (1 bit per pixel) so im trying to make 
  char array in dynamic memory allocation..</p>
  
  <pre><code>class pixmap
  {
  private:
      char _rows;
      int _width, _height;
      char **pix_m;
  public:
      pixmap(int , int);
      uint8_t getpixel(int, int);
      void printl(int);
  
  };
  </code></pre>
  
  <p>so what im trying to do is for example if i wanted pixel map of (100 x 100) .. i allocate 2d array of char [100][1+100/8] .. where the char stores 8 bits</p>
  
  <pre><code>pixmap::pixmap(int width, int height)
  {
      _width = width;
      _height = height;
      _rows = width/8+1;
  
      pix_m = (char**) (calloc(height,_rows));
      for (int x =0 ; x &lt; _rows; x++)
      {
             pix_m[x] = (char*)calloc(_rows,sizeof(char*));
      }
  
      printf("%d\r\n",_rows);
  }
  </code></pre>
  
  <p>this is my construct of the class ^^</p>
  
  <p>and here where i should print a row of pixels:</p>
  
  <pre><code>void pixmap::printl(int y)
  {
      int pix;
      for (int i = 0; i &lt; _rows-1; i++)
      {
          for (int x= 0; x&lt;8; x++)
          {
              pix = pix_m[y][i]&amp;(0x01&lt;&lt;(7-x));
              printf("%d",pix!=0);
          }
      }
      int q = _width - (_rows-1)*8;
      for (int x= 0; x&lt;q; x++)
      {
          pix = pix_m[y][_rows-1]&amp;(0x01&lt;&lt;(7-x));
          printf("%d",pix!=0);
      }
  }
  </code></pre>
  
  <p>and in main function :</p>
  
  <pre><code>int main()
  {
      pixmap img(50,100);
      img.printl(1);
  
      getch();
  }
  </code></pre>
  
  <p>the problem is when i try to print line bigger than 6 .. the program crashes .. shouldnt i be able to printl(0-99) ???</p>
  
  <p>the code : 
  <a href="http://pastebin.com/9X8r9PWe" rel="nofollow">http://pastebin.com/9X8r9PWe</a></p>