Copying an array of structs to device memory

Hi:

I’m facing trouble to copying an array of a struct (that contains a set of structs), and I’m a bit lost on how to solve it.
So, I had following code that is working for copying a single struct item

static void _cinit(memory** n) {
  memory t;
  BigInteger w;

  cudaMalloc(n, sizeof(memory));
  BImemcpy(&w, 2);

  //device memory
  cudaMalloc(&t.vt, sizeof(BigInteger));

  //some more cudaMalloc

  cudaMemcpy(((BigInteger*)t.vt), &w, sizeof(BigInteger), cudaMemcpyHostToDevice);
  cudaMemcpy(*n, &t, sizeof(memory), cudaMemcpyHostToDevice);
}

int main(){
  memory* m = NULL;

  _cinit(&m);
}

so, I modified the code to make it work as an array

static void _cinit(memory** n, int cnt) {
  memory t;
  BigInteger w;
  int i;

  //cudaMalloc(n, sizeof(memory)); --> commented this line
  BImemcpy(&w, 2);

  //device memory
  cudaMalloc(&t.vt, sizeof(BigInteger));

  //some more cudaMalloc

  cudaMemcpy(((BigInteger*)t.vt), &w, sizeof(BigInteger), cudaMemcpyHostToDevice);
  //cudaMemcpy(*n, &t, sizeof(memory), cudaMemcpyHostToDevice); --> commented this line


  for (i = 0; i < cnt; i++) {
    cudaMalloc(&n[i], sizeof(memory)); 
    cudaMemcpy(n[i], &t, sizeof(memory), cudaMemcpyHostToDevice);
    printf("memory %p set result: %s\n", n[i], cudaGetErrorString(cudaGetLastError()));
  }
}

int main(){
  int i;
  memory* m = NULL;

  _cinit(&m, 4);

  for(i = 0;i < 4;i++){
    printf("received memory: %p\n", &m[i]);
  }
}

after an execution, I found that after first position of the array, pointers are not matching, making impossible to use any array position after 0.

memory 0000000701440A00 set result: no error
memory 0000000701440C00 set result: no error
memory 0000000701440E00 set result: no error
memory 0000000701441000 set result: no error
received memory: 0000000701440A00 --> same memory pointer
received memory: 0000000701440AA0 --> different memory pointer
received memory: 0000000701440B40
received memory: 0000000701440BE0

Obviously I’m doing something wrong, but I’m not able to find it… can anyone provide some hints of what’s happening here?

Thanks.