Registered Member
|
Hi,
I currently have a multidimensional std::vector called "vecs". It has k vectors, each with 10 elements. I would like to map each of these vectors to an Eigen::VectorXd. I have the following code but at some point in my code, I get a heap corruption error. I've used the special allocator for STL containers as mentioned in the documentation (http://eigen.tuxfamily.org/dox/TopicStlContainers.html)
Could you please help me in correcting any mistakes in this code? Thank you for your help.
Last edited by a1re on Tue May 24, 2011 2:04 pm, edited 1 time in total.
|
Registered Member
|
I've never used the placement new. But I think that if you write "new (&v) Map<...>(...)" to make v map another piece of memory, then v should be of the type Map. However, in your code, t_vecs.at(i) is of type VectorXd. So my guess would be that you need to change the type of t_vecs as follows:
|
Registered Member
|
Thanks for your suggestion. However, it produces the compile time error 'no appropriate default constructor available'.
On another note, if I have k = 1 and change my code to use just one map of one std::vector, everything works well. It's only when k > 1 and I start mapping to multideminsional vectors that this heap corruption error occurs. I ended up just using a vector of Eigen::VectorXd at the beginning so there's no need to map it. It works now. Thank You. |
Moderator
|
Jitse's reply was correct, the problem is that Map does not have a default ctor so you connot simply create a std vector of Map. I don't know if using the vector(size,model) ctor will work:
Eigen::Map<Eigen::VectorXd> empty(0,0); std::vector<Eigen::Map<Eigen::VectorXd> > t_vecs(k, empty); no need for the aligned allocator here. |
Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar