42 questions
3 votes
1 answer
174 views
Alignment for vector of vectors in C++ templated type
In C++, what is the shortest way to declare a vector of vectors, where each inner std::vector's metadata fields (importantly size and pointer) have a user-chosen alignment? Ideally I'd be able to ...
18 votes
0 answers
117 views
Surprising cache line contention adjacent inherited members
In the critpath of a threaded app I've encountered a performance bottleneck. profiling indicates unexpected contention on cache lines despite what appears to be independent data access across ...
2 votes
1 answer
108 views
clang-19 and alignas new formatting
Prior to Clang 19, it was possible to write: struct alignas(8) my_struct { void* a_pointer; int a_variable; int _padding; }; However, in Clang 19, you must write: struct my_struct { ...
0 votes
1 answer
163 views
Valid positions of `alignas` inside a plain array definition
I'd like to understand the validity of different alignas specifier position within a plain array definition: constexpr std::size_t Required=16; alignas(Required) int iarr1[10]; // 1 int alignas(...
1 vote
1 answer
134 views
How to know the size of an aligned type including padding
I have a buffer with chunks that align to the cacheline size, but have arbitrary length, let's say 100 bytes. It is clear to me that the buffer (vector) elements are aligned on cacheline borders, but ...
-1 votes
1 answer
6k views
warning: memcpy forming offset [X, Y] is out of the bounds [0, 2] of object Z
I'm trying to assemble information in a struct to later memcopy it to an spi buffer. This is the code I'm working with: Demo #include <cstdio> #include <cstdint> #include <cstring> /*...
6 votes
2 answers
705 views
How to replace aligned_storage<T[]> with std::byte[]?
The use of aligned_storage is deprecated in C++23 and suggested to be replaced with an aligned std::byte[] (see here). I have two questions about this: 1. How to align this? The document suggests to ...
0 votes
1 answer
475 views
align array elements differently in aligned union
I'm using SSE/AVX and I need to store aligned data. how ever, my data can be of different types. so I use a union like this union Data { bool Bools[128]; int32 Ints32[128]; int64 Ints64[...
0 votes
0 answers
66 views
Can alignas be implemented with mmap?
I was wondering if someone can try to implement alignas with mmap by playing with the first parameter? If not, then can anyone try to implement alignas themselves?
0 votes
2 answers
834 views
why alignas(64) not aligned with 64
why alignas(64) not aligned with 64? for example: struct alignas(32) st32 { float a; uint16_t b; uint64_t c; }; struct alignas(64) st64 { float a; uint16_t b; uint64_t c; }; ...
1 vote
1 answer
607 views
What is the correct usage/syntax for the c++17 alignas() specifier for dynamically allocated arrays of fundamental types?
This must be a repeat question, but I have not found it after searching for 2 days ... I'm using MSVC with /std:c17 /std:c++17 and trying to get alignas(64) to work with arrays of doubles. The syntax ...
3 votes
2 answers
1k views
Is it correct to use alignas(16) for an array[8] of m128?
This is the code I usually write: alignas(16) __m128 myBuffer[8]; But maybe (since the object-array is 128*8 bit = 128 byte) I should write: alignas(128) __m128 myBuffer[8]; Or, "since the ...
0 votes
1 answer
281 views
error: storage class may not be specified here when using __align() in MDK ARM uVision v5 ARM Compiler 5
I am migrating a project from CubeIDE (GCC) to the most comprehensive software development solution for Arm®-based microcontrollers uVision (ARM Compiler 5) and have a difficulty using __align keyword....
2 votes
1 answer
686 views
C++ class specifier alignas option via template
Can C++ template parameters be used to control specifiers on the class itself to minimize some code duplication? For example: I have a class that I'd like to use both in a concurrent context (and ...
1 vote
0 answers
109 views
Alignment of a simple class to allow array access without UB
Suppose I have the following simple class: struct employee{ std::string name; short salary; std::size_t age; employee(std::string name, short salary, std::size_t ...