title: How to declare a struct with a dynamic array inside it in device
body: <p>How to declare a struct in device that a member of it, is an array and then dynamically allocated memory for this. for example in below code, compiler said: <code>error : calling a __host__ function("malloc") from a __global__ function("kernel_ScoreMatrix") is not allowed</code>. is there another way for perform this action?</p>
  
  <p>Type of<code>dev_size_idx_threads</code> is <code>int*</code> and value of it, sent to kernel and used for allocate memory.</p>
  
  <pre><code>struct struct_matrix
  {
      int *idx_threads_x;
      int *idx_threads_y;
      int thread_diag_length;
      int idx_length;
  };
  
  struct  struct_matrix matrix[BLOCK_SIZE_Y];
  
  matrix-&gt;idx_threads_x= (int *) malloc ((*(dev_size_idx_threads) * sizeof(int) ));
  </code></pre>