title: Using Shared & Constant Memory in CUDA
body: <p>I want to read a text file and store it in an array. Then, I want to transfer the array from the host to the device and store it in the shared memory. I have written the following code,but the execution time has been increased compared with using the global memory. I cannot understand what the reason can be? Also, it will be great if someone can help me write this code using constant memory.</p>
  
  <pre><code>__global__ void deviceFunction(char *pBuffer,int pSize){
      extern __shared__ char p[];
      int i;
      for(i=0;i&lt;pSize;i++)}
          p[i] = pBuffer[i];
      }
  }
  int main(void){
  
      cudaMalloc((void**)&amp;pBuffer_device,sizeof(char)*pSize);
      cudaMemcpy(pBuffer_device,pBuffer,sizeof(char)*pSize,cudaMemcpyHostTo Device);
      kernel&lt;&lt;&lt;BLOCK,THREAD&gt;&gt;&gt;(pBuffer_device,pSize);
  
  }
  </code></pre>