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

boost::any and unaligned arrays

Tags: None
(comma "," separated)
smithericsmith
Registered Member
Posts
3
Karma
0

boost::any and unaligned arrays

Wed Jun 08, 2011 3:05 pm
I am wondering if anyone has come across an elegant solution regarding using fixed-size vectorizable Eigen types (and types that contain such types) within a boost::any...

The issue is that boost::any uses a container class (holder<T>) to actually hold the value of the boost::any. This container class has a member 'held' which is of type T. Imagine that T is Eigen::Vector4f, and you can see that holder<T> needs to have its new overloaded to return a 16-byte aligned pointer. Unfortunately this container class (holder<T>) is not easily modified, as it is really an internal class defined within boost::any.

So has anyone figured out a nifty way to get around this issue?

eigen 3.0.1
boost 1.43

Thanks,

Eric
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: boost::any and unaligned arrays

Wed Jun 08, 2011 4:39 pm
note that you can locally give up vectorization by using, e.g.,

Eigen::Matrix<float,4,1,Eigen::DontAlign>

instead of Vector4f. Such objects will still be compatible with Vector4f ones, so you can copy the held object into Vector4f before actually using it.
smithericsmith
Registered Member
Posts
3
Karma
0

Re: boost::any and unaligned arrays

Thu Jun 09, 2011 1:31 pm
ggael wrote:note that you can locally give up vectorization by using, e.g.,

Eigen::Matrix<float,4,1,Eigen::DontAlign>

instead of Vector4f. Such objects will still be compatible with Vector4f ones, so you can copy the held object into Vector4f before actually using it.


ggael,

Thanks for the response. Unfortunately in my exact circumstance, this would not be practical, as what I am actually putting in the boost::any is an object of a class that has an Eigen::Vector4f member. Therefore it would be quite difficult to attempt to change it to use a non-aligned version locally. That said, the 'Eigen::DontAlign' specifier is a tool that I didn't know that I had and I may be able to use it elsewhere.

Thanks,

Eric
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: boost::any and unaligned arrays

Thu Jun 09, 2011 2:47 pm
I see,

perhaps a ugly solution would be to template specialize holder<> for your type.
smithericsmith
Registered Member
Posts
3
Karma
0

Re: boost::any and unaligned arrays

Thu Jun 09, 2011 5:43 pm
ggael wrote:I see, perhaps a ugly solution would be to template specialize holder<> for your type.


Yes, that would be a solution. Hopefully it won't come to that :)


Bookmarks



Who is online

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