This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Create multiple maps to multidimensional std::vector

Tags: None
(comma "," separated)
a1re
Registered Member
Posts
16
Karma
0
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)

Code: Select all
std::vector<Eigen::VectorXd, Eigen::aligned_allocator<Eigen::VectorXd> > t_vecs.at(k);

for (int i = 0; i < k; i++){
   new (&t_vecs.at(i)) Eigen::Map<Eigen::VectorXd>(vecs.at(i).at(0), 10);
}


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.
jitseniesen
Registered Member
Posts
204
Karma
2
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:

Code: Select all
std::vector<Eigen::Map<Eigen::VectorXd>,
            Eigen::aligned_allocator<Eigen::Map<Eigen::VectorXd> > > t_vecs(k);
a1re
Registered Member
Posts
16
Karma
0
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.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
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.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar