Featured post
c++ - How to use Memcpy() function -
i want use memcpy in end, instead of
block_orig_left[i1][j1]=block_orig[i1][j1]; pred_orig_left [i1][j1]=block_pred[i1][j1];
i have error using memcpy
src/coder.c:909: error: invalid operands binary * (have ‘unsigned int’ , ‘int **’)
src/coder.c:910: error: invalid operands binary * (have ‘unsigned int’ , ‘int **’)
int **block_orig_left=null; block_orig_left=intmatrix(bsize_y_level[levelv], bsize_x_level[levelv]); pred_orig_left=intmatrix(bsize_y_level[levelv], bsize_x_level[levelv]); for(i1=0; i1<bsize_y_level[levelv]; i1++) for(j1=0; j1<bsize_x_level[levelv]; j1++) { block_orig_left[i1][j1]=block_orig[i1][j1]; pred_orig_left[i1][j1]=block_pred[i1][j1]; average_block_orig_left+=block_orig[i1][j1]; } memcpy(block_orig_left, block_orig, sizeof(int **)*block_orig); memcpy(pred_orig_left, block_pred, sizeof(int **)*block_pred);
how use memcpy correctly?
you multiplying size of int** int**, doesn't make sense. in other words, if wanted know weight of cars on truck, can't multiply "weight of 1 car" "truck". have multiply weight of 1 car number of cars on truck.
the third parameter memcpy number of bytes want copy. correctly getting size of int*, want multiply number of int* in structure. so, if i'm understanding code correctly, want use
sizeof(int**) * bsize_y_level[levelv] * bsize_x_level[levelv]
since structures copying seem contain many int double pointers.
edit: looking @ david yaw's answer, realize correct. failed address fact inner pointers not allocated @ once, rather in loop or something, need copied in manner. way above copy right amount of memory, not correct memory.
- Get link
- X
- Other Apps
Comments
Post a Comment