memory-alignment Questions
7
Solved
To prevent false sharing, I want to align each element of an array to a cache line. So first I need to know the size of a cache line, so I assign each element that amount of bytes. Secondly I want ...
Rival asked 2/9, 2011 at 9:43
0
I'm moving some C++17 code to be used in a project that is built with Qt, on Windows, using MinGW 7.3.0, and noticed something weird happening in the 32bit builds:
#include <cstddef>
#includ...
Broads asked 14/11, 2019 at 15:19
4
Solved
Given
template <typename T>
struct Vector3d { T x, y, z; };
Is it safe to assume that x, y, and z are in contiguous memory locations?
Is it at least safe to assume that for T = float and ...
Nimrod asked 5/9, 2019 at 15:27
4
Solved
I can't explain the execution behavior of this program:
#include <string>
#include <cstdlib>
#include <stdio.h>
typedef char u8;
typedef unsigned short u16;
size_t f(u8...
Braunite asked 17/10, 2017 at 12:48
2
Solved
Consider working on an x64 bit Windows operation system with the following type alignments:
As far as I understand, it is very bad to do something like this:
struct X_chaotic
{
bool flag...
Scoliosis asked 28/7, 2019 at 20:37
7
Solved
[Not a duplicate of Structure padding and packing. That question is about how and when padding occurs. This one is about how to deal with it.]
I have just realized how much memory is wasted as a re...
Kaitlin asked 25/6, 2019 at 20:29
3
Solved
In C++, on at least GCC and Clang, an over-aligned type embedded within a container (std::vector) seems to be treated differently depending on whether the type is an over-aligned struct or an over-...
Norty asked 25/6, 2019 at 19:32
2
Solved
I am currently learning the basics of assembly and came across something odd when looking at the instructions generated by GCC(6.1.1).
Here is the source:
#include <stdio.h>
int foo(int x, i...
Sustainer asked 5/8, 2016 at 4:27
4
Solved
I was wondering whether the compiler would use different padding on 32-bit and 64-bit systems, so I wrote the code below in a simple VS2019 C++ console project:
struct Z
{
char s;
__int64 i;
};
...
Dilator asked 30/4, 2019 at 11:38
2
I have a type that is declared with __attribute__((aligned(16))). When building with clang on OS X on x86_64, the following code causes a GP fault when attempting to throw a value containing this t...
Adjunction asked 17/6, 2015 at 8:19
2
The C++17 standard uses the term "allocation unit" several times in section 12.2.4 when discussing bit-fields but doesn't seem to define what the term means. The standard also states, "As a special...
Communalize asked 16/2, 2019 at 4:55
1
Is sizeof(Type) always divisible by alignof(Type)
such that this statement will always be true? sizeof(Type) % alignof(Type) == 0
Scutch asked 27/1, 2019 at 2:13
1
Solved
I have a problem that I need to understand if there is a better solution. I have written the following code to pass a few variables from a writer thread to a reader thread. These threads pinned to ...
Teter asked 23/12, 2018 at 19:29
3
Solved
This statement in the article made me embarrassed:
C permits an implementation to insert padding into structures (but not into arrays) to ensure that all fields have a useful alignment for the t...
Frag asked 6/10, 2018 at 23:28
1
Solved
I use __int128 as struct's member.
It works find with -O0 (no optimization).
However it crashes for segment fault if optimization enabled (-O1).
It crashes at instruction movdqa, which need the v...
Franni asked 27/9, 2018 at 7:29
1
Solved
I'm trying to educate myself regarding stack overflows and played around a bit with these -fno-stack-protector flag and tried to understand how memory is managed in a process.
I compiled the follo...
Ideologist asked 9/9, 2018 at 23:11
3
Solved
The function mkl_malloc is similar to malloc but has an extra alignment argument. Here's the prototype:
void* mkl_malloc (size_t alloc_size, int alignment);
I've noticed different performances w...
Unpleasant asked 3/8, 2018 at 1:6
3
Solved
I'm curious to see if my 64-bit application suffers from alignment faults.
From Windows Data Alignment on IPF, x86, and x64 archive:
In Windows, an application program that generates an alignment ...
Dragnet asked 13/11, 2014 at 22:2
2
Solved
I need to align a struct to a 16 byte boundary in Rust. It seems possible to give hints about alignment through the repr attribute, but it doesn't support this exact use case.
A functional test of ...
Counterespionage asked 6/9, 2015 at 20:47
1
Solved
I've searched through the standard about unaligned access, but didn't find anything (maybe I was inadvertent).
Is it undefined behavior? Is it implementation defined?
As a lot of current CPUs sup...
Skilful asked 1/7, 2018 at 19:13
2
Solved
Could some please explain, what is really wrong with the following example, especially the part with "which might result in the 32-bit unsigned long being loaded from an address that is not a multi...
Trichroism asked 17/6, 2018 at 18:3
2
Solved
My understanding is that vectorization of code works something like this:
For data in array bellow the first address in the array that is the multiple of 128(or 256 or whatever SIMD instructions r...
Magnification asked 17/5, 2018 at 22:21
1
Solved
I've read in different places that it is done for "performance reasons", but I still wonder what are the particular cases where performance get improved by this 16-byte alignment. Or, in any case, ...
Equalizer asked 20/3, 2018 at 17:48
7
Solved
Is there a way in gcc or clang (or any other compiler) to spit information about whether a struct has holes (memory alignment - wise) in it ?
Thank you.
ps: If there is another way to do it, pl...
Boccie asked 6/10, 2011 at 12:17
0
I am trying to use aligned_alloc in my C++ code but it fails to compile:
cc1plus: warning: command line option '-std=c11' is valid for C/ObjC but not for C++
vec.cpp: In function 'int main()':
vec...
Mid asked 16/2, 2018 at 3:53
© 2022 - 2024 — McMap. All rights reserved.