title: how can i overcome memory allocation in cuda
body: <p>I have a question. I'm working with the 4.0 cuda.
  I have the following code:</p>
  
  <p>in my cudaHeader.h:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  extern "C" void wrapperfunction(int* array);
  </code></pre>
  
  <p>in my cudaCpp.cpp:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  ......
  int main()
  {
    int array[50] = {0, 1, 2, ..........,49};
    ...........
  
    while(true)
    {
     ........
  
     wrapperfunction(array);
  
     ........
  
     }
    return 0;
  
  }
  </code></pre>
  
  <p>in my cuda.CU:</p>
  
  <pre><code>__global__ void kernel(int *new_arrayG, int *arrayG,int *const_arrayG)
  {
    int x = threadIdx.x;
  
    new_arrayG[x] = arrayG[x] + const_arrayG[x];
    __syncthreads();
  }
  
  extern "C" int wrapperfunction(int* array)
  {
  
    static int const_array[50] = {0, 1, 2, ........., 49};  //any constant data
    int *arrayG, *new_arrayG, *const_arrayG;
    int size = 50 * sizeof(int);
  
    cudaMalloc((void**)&amp;arrayG, size);
    cudaMalloc((void**)&amp;new_arrayG, size);
    cudaMalloc((void**)&amp;const_arrayG, size);
  
    cudaMemcpy(const_arrayG, const_array, size, cudaMemcpyHostToDevice);
    cudaMemcpy(arrayG, array, size, cudaMemcpyHostToDevice);
  
    Kernel&lt;&lt;&lt;1, 50&gt;&gt;&gt;(new_arrayG, arrayG, const_arrayG);
  
    cudaMemcpy(array, new_arrayG, size, cudaMemcpyDeviceToHost);
  
    cudaFree(arrayG);cudaFree(new_arrayG);cudaFree(const_arrayG);
  }
  </code></pre>
  
  <p>this a sample from my code, i wanna to say each time i call the wrapperfunction from my .cpp code the program allocate the static array and free it at the end and it it takes much time and at real i deal with very large static array and each time call this function i take very much time. so i wanna to a way to allocate my static arrays one time at the begining of the program and free them at the end of my program(application).
  Plz. any helping.</p>
  
  <p>Thanks.</p>