memory-alignment Questions

2

Some CPU architectures (other than x86) dislike reading and writing multibyte numbers at unaligned addresses so much that they raise SIGBUS exception upon detecting this and forcing the programmer ...
Coster asked 11/2, 2015 at 16:55

2

Solved

how is the value of 28h (decimal 40) that is subtracted from rsp calculated in the following: option casemap:none includelib kernel32.lib includelib user32.lib externdef MessageBoxA : near ex...

1

The context is: One would like to get a fairly well aligned memory, e.g. for allowing the compiler to use AVX, AVX2 . At the same time, one attempts to keep the code as portable as reasonably possi...
Strata asked 13/1, 2015 at 23:7

4

Solved

Consider the following C struct and C++ struct declarations: extern "C" { // if this matters typedef struct Rect1 { int x, y; int w, h; } Rect1; } struct Vector { int x; int y; } struct Rect...
Salmanazar asked 8/1, 2015 at 4:21

2

Solved

I've implemented a jagged multi-dimensional array by allocating the space for the intermediate arrays as well as the actual elements in 1 large block. While working on this I figured I had to take ...
Melliemelliferous asked 31/12, 2014 at 4:50

1

Solved

When allocating an std::aligned_storage<2, 4096>::type on the heap I always get a pointer that is offset by 16 bytes (on x64; on x86 it is offset by 8 bytes). In other words, this: #include ...
Pinckney asked 30/11, 2014 at 20:6

1

Solved

Stroustrup in his new book in page 151 shows the following example of the use of the type specifier alignas: Sometimes, we have to use alignment in a declaration, where an expression, such as a...
Grundy asked 7/11, 2014 at 17:6

2

I am porting some software from the gcc-toolchain to the armcc-toolchain (processor stays the same (Cortex-A9)). In the C-code memcpy is used. armcc replaces a call to memcpy by a call to __aeabi_m...
Tyrr asked 22/7, 2014 at 9:18

4

Solved

While going through one project, I have seen that the memory data is "8 bytes aligned". Can anyone please explain what this means?
Container asked 17/5, 2010 at 5:53

1

Solved

I am following Stefanus Du Toit's hourglass pattern, that is, implementing a C API in C++ and then wrapping it in C++ again. This is very similar to the pimpl idiom, and it is also transparent to t...
Langur asked 20/10, 2014 at 17:44

2

I hope that I have reduced my question to a simple and reproducible test case. The source (which is here) contains 10 copies of an identical simple loop. Each loop is of the form: #define COUNT (...
Burst asked 8/10, 2014 at 21:41

2

Solved

I have a huge source code that works on PowerPC. I need to port it to ARM. But, ARM generates h/w exception on unaligned memory accesses. So, I want to find all the possible instances where the una...
Foreland asked 11/9, 2014 at 10:43

1

Solved

I understand that gcc has an option -Wcast-align which warns whenever a pointer is cast such that the required alignment of the target is increased. Here's my program: char data[10]; int ptr = *((i...
Plasticize asked 10/9, 2014 at 9:43

3

Solved

I have a structure of which I want to calculate its size: #pragma pack(push,4) struct MyStruct { uint32_t i1; /* size=4, offset=0. */ uint32_t i2; /* size =4 offset =4 */ uint16_t s1; /* size ...
Sulfide asked 12/8, 2014 at 11:52

3

While thinking of a counter-example for this question, I came up with: struct A { alignas(2) char byte; }; But if that's legal and standard-layout, is it layout-compatible to this struct B? st...
Salyers asked 1/2, 2014 at 15:33

2

Solved

There is a quote from cppreference: Every object type has the property called alignment requirement, which is an integer value (of type std::size_t, always a power of 2) representing the number of...
Sculptress asked 16/7, 2014 at 18:39

4

In Noda Time v2, we're moving to nanosecond resolution. That means we can no longer use an 8-byte integer to represent the whole range of time we're interested in. That has prompted me to investiga...
Slumber asked 14/7, 2014 at 17:30

1

Solved

In my project I changed the used point type from Eigen::Vector2f to Eigen::Vector2d and ran into the alignment problem. Here is a simplified version of the code: #include <vector> #include ...
Loricate asked 19/6, 2014 at 16:11

3

Solved

Compiling with VS2012 and working with the DirectXMath library, I encountered an issue where it appeared that the compiler wasn't aligning my XMMATRIX. I simplified the issue down to the following....

4

Solved

Let's consider the structs : struct S1 { int a; char b; }; struct S2 { struct S1 s; /* struct needed to make this compile as C without typedef */ char c; }; // For the C++ fans struct S3 : S...
Underhand asked 8/6, 2014 at 20:10

2

Solved

I have tested this code on ideone.com and it outputs 16 as it should. However when I try it in Visual Studio 2013 it shows 8. Is it a bug or lack of C++11 support from the compiler? #include <i...
Natoshanatron asked 4/6, 2014 at 19:23

3

Solved

I am having trouble aligning memory for DMA transfer on the Cell processor. I need the last 4 bits of an address to be 0. I have 4 arrays of unsigned int where each element must be aligned in memo...
Octachord asked 29/4, 2014 at 14:43

1

Solved

The C11 standard added the aligned_alloc function to allocate uninitialized aligned memory. The standard also includes the calloc function to allocate memory which is initialized to zero but only a...
Ichthyic asked 15/4, 2014 at 19:24

3

Solved

I am trying to align data members by using #pragma pack (n). Take the following as an example: #include <iostream> using namespace std; #pragma pack(8) // or (16) struct A { int a; char ...

4

Solved

Following the discussion from this post, I have understood that the main reason for the alignment of structure members is performance (and some architectures restrictions). If we will investigate ...
Foreandaft asked 19/6, 2012 at 19:50

© 2022 - 2024 — McMap. All rights reserved.