Dynamically allocating StaticVector instances?

Issue #191 wontfix
Антон М created an issue

Sorry if I am missing something obvious, just started to use blaze. For me the following code segfaults in the StaticVector copy constructor:

    std::vector<blaze::StaticVector<float, 32>> vec;
    for (auto i = 0u; i < 100; i++) vec.emplace_back();

Is this expected?

Comments (2)

  1. Klaus Iglberger

    Hi Антон!

    Thanks for creating this issue. The problem is the default allocator of std::vector, which does not provide the right alignment for its data. In order to adhere to the alignment restrictions of StaticVector, please use a blaze::AlignedAllocator:

    using VT = blaze::StaticVector<float, 32>;
    std::vector<VT,blaze::AlignedAllocator<VT>> vec;
    for (auto i = 0u; i < 100u; ++i) vec.emplace_back();
    

    That will fix the problem.

    Best regards,

    Klaus!

  2. Klaus Iglberger

    Hi Антон!

    The alignment requirements of a StaticVector data member are "inherited" by the containing struct. Therefore the solution will also work in this scenario. Unfortunately both the wiki and the tutorial are a little silent on this kind of issue. We should extend both to help users to avoid this kind of problem.

    Best regards,

    Klaus!

  3. Log in to comment