1 | initial version |
reserve() does NOT allocate any data. the correct way to do this would be:
// a row vector, safe to iterate from pb[0] to pb[9], given: int *pB = B.ptr<int>(0);
Mat_<int> B(1,10);
// a col vector, safe to do: int *pB = B.ptr<int>(i); and pb[0]
Mat_<int> B(10,1);
Mat is essentially a 2d container, if you want it to behave like a std::vector, why not use one in the 1st place ?
2 | No.2 Revision |
reserve() does NOT allocate any data. the correct way to do this would be:
// a row vector,
Mat_<int> B(1,10);
int *pB = B.ptr<int>(0);
// now it's safe to iterate from pb[0] to pb[9], given: pb[9] int *pB = B.ptr<int>(0);
Mat_<int> B(1,10);
// a col vector, safe to do: vector
Mat_<int> B(10,1);
int *pB = B.ptr<int>(i); and pb[0]
Mat_<int> B(10,1);
B.ptr<int>(i);
// careful, all you can use is pb[0] !
Mat is essentially a 2d container, if you want it to behave like a std::vector, why not use one in the 1st place ?