Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2bdca7

Browse files
committed
add explanations why fix in prev. commit is valid
1 parent 03ba62e commit a2bdca7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

matplotlibcpp.h

+6
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ template <typename Vector> PyObject *get_array(const Vector &v) {
393393
npy_intp vsize = v.size();
394394
// Eigen Vectors do not support begin/end() in the currently stable version
395395
// this can be changed once Eigen 3.4. is released
396+
// data() returns a pointer to the storage of the first element. If the
397+
// vector is modified afterwards, it may be rendedered invalid.
398+
// Note, that this is not an issue since get_array() is called by a
399+
// plot command using the instantaneous state of the vector.
400+
// The pointer is not reused. If the vector is plotted anew, data() is
401+
// called again and again get's the current, valid storage location.
396402
std::copy(v.data(), v.data() + v.size(), vd.begin());
397403
PyObject *varray =
398404
PyArray_SimpleNewFromData(1, &vsize, NPY_DOUBLE, (void *)(vd.data()));

0 commit comments

Comments
 (0)