Skip to content

Enhancement discussion

s-trinh edited this page Mar 30, 2017 · 6 revisions

vpArray2D class

Behavior of vpArray2D::resize()

The purpose of this section is just to record the behavior of vpArray2D::resize() in some possibly edge cases (on gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609).

vpMatrix null_matrix(6,0);
std::cout << "(null_matrix.data == NULL)? " << (null_matrix.data == NULL) << std::endl;
null_matrix.resize(0,1);
std::cout << "(null_matrix.data == NULL)? " << (null_matrix.data == NULL) << std::endl;
null_matrix.resize(0,2);
std::cout << "(null_matrix.data == NULL)? " << (null_matrix.data == NULL) << std::endl;

(null_matrix.data == NULL)? 0

(null_matrix.data == NULL)? 1

(null_matrix.data == NULL)? 0

This comes from the behavior of realloc when new_size is zero:

If new_size is zero, the behavior is implementation defined (null pointer may be returned (in which case the old memory block may or may not be freed), or some non-null pointer may be returned that may not be used to access storage).

int* ptr = NULL;
ptr = (int*) realloc(ptr, 0);
std::cout << "(ptr==NULL)? " << (ptr==NULL) << std::endl;
ptr = (int*) realloc(ptr, 0);
std::cout << "(ptr==NULL)? " << (ptr==NULL) << std::endl;

(ptr==NULL)? 0

(ptr==NULL)? 1

At the end, there should be no problem with this behavior.

Dimension of vpColVector and vpRowVector whith resize(0):

  • colNum is always equal to one with vpColVector, when calling resize(0) dimension [row,col] is [0x1]
  • rowNum is always equal to one with vpRowVector, when calling resize(0) dimension [row,col] is [1x0]

This should not be a problem at all (there was a small bug but can be fixed easily).