title: How to allocate Dynamic Memory to Device Pointer variable in C++ CUDA
body: <p>all programmers.
  I'm converting the existing C++ project to CUDA enhanced program.
  I'm new to CUDA. So I'm learning during work.
  I have to allocate memory to a dynamic struct member variable and the struct variable is allocated as device variable.</p>
  
  <p>like this:</p>
  
  <pre><code>_cuda_params* dcuda_params;
  
  cudaMalloc(&amp;dcuda_params, sizeof(_cuda_params));
  
  cudaMemcpy((void *)dcuda_params, (void*)cuda_params, sizeof(_cuda_params), cudaMemcpyHostToDevice);
  
  dcuda_params-&gt;DPht = (hashtb_entry *)malloc(c);  // c is size to allocate.
  </code></pre>
  
  <p>But during run time I get Exception 0xC0000022.
  I also tried this:</p>
  
  <pre><code>cudaMalloc(&amp;dcuda_params-&gt;DPht, c);
  </code></pre>
  
  <p>but the result is the same.
  How can I handle this?</p>
  
  <pre><code>.h file
      typedef struct {
          int blocksPerGrid;
          int threadsPerBlock;
          uint64_t HASH_SIZE;
          hashtb_entry* DPht;
      } _cuda_params;
  
  .cu file
  
  void _GpuSearch(_cuda_params* cuda_params){
  ...
          _cuda_params* dcuda_params;
          cudaMalloc(&amp;dcuda_params, sizeof(_cuda_params));
          cudaMemcpy((void *)dcuda_params, (void*)cuda_params, sizeof(_cuda_params), 
          cudaMemcpyHostToDevice);
          dcuda_params-&gt;DPht = (hashtb_entry *)malloc(c); //c: size to allocate.
  ...
  }
  </code></pre>