vendredi 27 octobre 2017

std::memcpy and copying data from 2D vector

I have int *a with for 5x4 matrix, where 5 is row and 4 is column.

The memory allocation for a matrix is column are continuous and every row is started after individual column.

I like to copy data from vector< vector <int>> b;

b also have same size and dimension have 5 rows and 4 columns.

How I obtained data for b is

b.resize(5);
for(int i = 0; i < 5; i++){
    b[i].resize(4);
}

I like to copy data from b to a. Is it possible to use std::memcpy(a, &b, sizeof (int)*20)?

Aucun commentaire:

Enregistrer un commentaire