title: How to assign values already stored in fixed memory to a cimg object
body: <p>I am using the Cimg lib to do the image processing work. I have the pointer of an array returned by GPU, and I want to the Cimg object to take the value of the array directly. Now, I am using the for loops to do the work, but it is not very efficient. </p>
  
  <p>The sample codes I am using now is as follows:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  #include "CImg.h"
  
  using namespace std;
  using namespace cimg_library;
  
  int main(){
      char pause;
      int width=3; int height=3;//Dimension of the Cimg matrix
      int size = width * height * sizeof(int); // number of bytes in total in arrays
      int *ptr = (int*) malloc(size);
  
      //Assign the array some example value; 
      for (int m=0;m&lt;width*height;m++){
          *(ptr+m)=m;
      }
  
      CImg&lt;int&gt; img(width,height,1,1);
  
      //This is how I assign the value of the array to the Cimg object
      for (int i=0;i&lt;width;i++)
          for (int j=0;j&lt;height;j++)
          {
              img.atXY(i,j)=*(ptr+j*width+i);
          }
  
          img.save_bmp("img.bmp");
          cout&lt;&lt;"Pause:";
          cin&gt;&gt;pause;
      }
  }
  </code></pre>
  
  <p>I tired this code, but it does not work:</p>
  
  <pre><code>img.begin()=ptr;
  </code></pre>
  
  <p>Anyone can help me to eliminate the for loops and improve the speed? Thank you all in advance.</p>