pushing front new elements in vector

0

i want to implement a vector that contains elements of VectorXd and the max size of vector is 7. and when adding new values.It will be added at front of the vector and when the size of vector equals to 7, then the last element will be deleted. my implementation has error due to this functions will be called almost 30000 times. Often, After the call of 50 time, i get this error.

Exception thrown at 0x0F593B30 (vcruntime140d.dll) in lotka2.exe: 0xC0000005: Access violation reading location 0x00000000.

template<typename T> struct smart_copy_helper<T,true> {
  EIGEN_DEVICE_FUNC static inline void run(const T* start, const T* end, T* target)
  {
    IntPtr size = IntPtr(end)-IntPtr(start);
    if(size==0) return;
    eigen_internal_assert(start!=0 && end!=0 && target!=0);
    std::memcpy(target, start, size);
  }
};

My code is

void Scheduler::push_front(Eigen::VectorXd new_value) {

         \\ std::vector<Eigen::VectorXd> yi;

        this->yi.insert(yi.begin(), new_value);

        

        if (this->yi.size() == 7) {
            this->yi.pop_back();
        }
    }

Can someone help? with efficient solving as possible. when i debugged, the problem with this->yi.insert(yi.begin(), new_value);

c++
asked on Stack Overflow Sep 22, 2020 by Abdelrahman Elayashy • edited Sep 22, 2020 by Abdelrahman Elayashy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0