title: ” Renderscript Allocation copyto “ cost time a lot, how to solve it?
body: <pre><code>void sobel(const uchar * v_in , uchar4 *v_out, const void * userData , uint32_t x , uint32_t y)
  {
      if ((x==0)||(x==width-1)||(y==0)||(y==height-1)) return;
  
      uchar a00 = rsGetElementAt_uchar(gIn,x-1,y-1); 
      uchar a01 = rsGetElementAt_uchar(gIn,x,y-1);
      uchar a02 = rsGetElementAt_uchar(gIn,x+1,y-1);
      uchar a10 = rsGetElementAt_uchar(gIn,x-1,y);
      uchar a11 = rsGetElementAt_uchar(gIn,x,y);
      uchar a12 = rsGetElementAt_uchar(gIn,x+1,y);
      uchar a20 = rsGetElementAt_uchar(gIn,x-1,y + 1);
      uchar a21 = rsGetElementAt_uchar(gIn,x,y + 1);
      uchar a22 = rsGetElementAt_uchar(gIn,x+1,y + 1);
  
  
      short ux = ((short)((a20) * (1) + (a21) * (2) + (a22) * (1) + (a00) * (-1) + (a01) * (-2) + (a02) * (-1)));
      short uy = ((short)((a02) * (1) + (a12) * (2) + (a22) * (1) + (a00) * (-1) + (a10) * (-2) + (a20) * (-1)));
  
      uchar resx = (NDA_CAST_8U(ux));
      uchar resy = (NDA_CAST_8U(uy));
  
      //outdata[y*width + x] = resx;
  
      rsSetElementAt_uchar(gUx,resx,x,y);
      rsSetElementAt_uchar(gUy,resy,x,y);
  
      uchar res  = 255 * (uchar)(ux &gt; 10 || uy &gt; 10 );
      *v_out = (uchar4){res,res,res,255};
  }
  </code></pre>
  
  <p>I'm confused about renderscript. I just want use it to do Imageprocess <code>sobel (image size : 640 * 480</code>; I tried to use JNI to do <code>sobel</code>, but it takes 3.5ms, which is too long. Frame-per-frame, with the byte data I get from camera <code>surfaceview</code>, I find that, whether I code or use the api <code>ScriptIntrinsicConvolve3x3</code>, the copyto and copyfrom operation take a lot of time (about 15ms). I'm wondering why the allocation is so slow and what I can do about this.</p>