1

I am trying to use memcy to copy an sub-array of an updated array A into an array B. Both A and B array have the same number of dimensions. The data going into array A is in the order of A.get_size(3) (Let's call dimension N here). Each update N will increase by 3(That means 3 set of data is added queueing in terms of dimension N). I need B to obtain the updated data (sub-array)only and the next copy will replace the previous 3. So I guess copy array A starting from (N-2) into B could do the job.

//initializing a new array B to obtain sub-array from A 
array B(A.get_size(0), A.get_size(1), A.get_size(2), 3, A.get_size(4));

//Get the forth dimension N 
N=A.get_size(3);

//copy the sub-array of A (from N-2 to N) into B(from 1 to 3 in dimension N)
memcpy(B.begin()+A.get_size(0)*A.get_size(1)*A.get_size(2)*(1)*A.get_size(4), A.begin()+A.get_size(0)*A.get_size(1)*A.get_size(2)*(N-2)*A.get_size(4), sizeof(T)*(A.get_size(0)*A.get_size(1)*A.get_size(2)*A.get_size(4)));

However, this could copy the number of elements but not the data value inside. Does it mean it gets memory leak? How should I make changes? Thanks!

Edited: Thanks to the comments, I tried to use std::copy instead of memcpy, but this does not work in this case because the array A contain complex float. It gives this error when compiling,

error: no matching function for call to ‘copy(std::complex<float>*, const std::complex<float>*, long unsigned int)’

Anymore ideas except from using std::copy? Thanks!

Cii
  • 133
  • 8

0 Answers0