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

Unaligned arrays assert with allocate_shared in VS2017

Tags: None
(comma "," separated)
xerion
Registered Member
Posts
20
Karma
0
From what I read the solution to using std::make_shared with eigen was to use std::allocate_shared and the aligned_allocator.

So that is exactly what I did but had no success.
The code below showcases the issue.

Code: Select all
class Foo
{
   Vec4d v;
public:
   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

auto test = std::allocate_shared<Foo>(Eigen::aligned_allocator<Foo>());


I should say that this works fine

Code: Select all
std::shared_ptr<Foo> test2(new Foo());


Am I missing something or this is something that has to be reported to MS ?

Thanks in advance
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I would recommend to not bother and use unaligned types as data member:

typedef Matrix<double,4,1,DontAlign> UVec4d;

then you, your collaborators, lib's users etc. will be safe!

Of course, you can still use aligned Vec4d everywhere else.
xerion
Registered Member
Posts
20
Karma
0
Thanks ggael.

I think there is light at the end of the tunnel with C++17.
It seems that operator new has been overleaded to support custom alignments that are set with alignas()

Code: Select all
void* operator new  ( std::size_t count, std::align_val_t al);
void* operator new[]( std::size_t count, std::align_val_t al);
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
indeed, in c++17 operator new will be aware of alignement :) Ironically, alignement is becoming less and less important with newer CPU generations...


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]