Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, February 25, 2007 6:50 PM
I just know the copyTo function is only suitable for 1-d array . But how about 2-d array? is there any faster and easier method that can copy all elements to another 2d array without using any loops to go through each elements? thanks!!
All replies (4)
Monday, February 26, 2007 3:56 AM âś…Answered
I guess you mean to use memcpy to copy the massive of memory space for a 2-d array to another memory space that has already allocated correctlly. For example:
int a[2][5],b[2][5];
for(int i=0;i<2;i++)
for(int j=0;j<5;j++)
a[j] = i+j;
memcpy(b,a,sizeof(a)); // This will copy entire a to b
Be careful that b has been allocated with enough space.
Is this what you want?
regards,
rico
Sunday, February 25, 2007 7:35 PM
I need more context. Could you provide a reference to the copyTo function. Thanks.
Sunday, February 25, 2007 9:40 PM
Boost.org has a multidimensional class. I don't know for sure that it has a copy function such as you need but I assume it does.
Monday, February 26, 2007 12:13 PM
yeah thz rico thats what i want ...
is that is just simply type this line of code memcpy(b,a,sizeof(a));
do i need to include any class or anything else?
thanks~