2

In the code shown below, i want to align buffer to a 64 byte boundary

#include <vector>
#include <iostream>

int main()
{
    using Buffer    = alignas(64) std::vector<char>;

    Buffer buffer;

    buffer.push_back('a');
    buffer.push_back('b');
    buffer.push_back('c');

    for (auto& i : buffer)
        std::cout << i << "\n";
}

When i compile the code, i get the following warning.

warning: ignoring attributes applied to class type β€˜std::vector<char>’ outside of definition [-Wattributes]
     using Buffer    = alignas(64) std::vector<char>;
                                        ^~~~~~~~~~~~

What am i doing wrong here? How to define a vector that is aligned to a 64 byte boundary?

EDIT: I want to align the underlying data that the vector owns. Is it possible to align that to a 64 byte boundary when using std::vector?

karthik
  • 21
  • 3
  • Are you trying to align the _vector_ to a 64-byte boundary or the underlying data that the vector owns? – Barry Mar 17 '19 at 19:50
  • I want to align the underlying data that the vector owns. Is it possible to align that to a 64 byte boundary when using std::vector? – karthik Mar 17 '19 at 19:54

0 Answers0