Skip to main content
Filter by
Sorted by
Tagged with
14 votes
4 answers
1k views

C89 and C99 do not provide an alignof macro as part of the standard library (nor an alignof keyword as part of the language as done by C23). C programmers found out they can define their own version ...
Random Citizen's user avatar
1 vote
1 answer
97 views

When supported, compressed instructions (RVC) bring a relaxation of code address alignment from 4 to 2 bytes. They also bring the possibility to intermix compressed and non-compressed instructions. ...
EnzoR's user avatar
  • 3,500
4 votes
1 answer
109 views

Does the C++17 standard requires #include <cstddef> static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ >= alignof(std::max_align_t)); to be true? In other words, is it safe to assume the address ...
Giovanni Cerretani's user avatar
3 votes
0 answers
101 views

I want to load 4 floats per thread. I know they are not 16 byte aligned. What is the best way to do this? Specific conditions: I cannot align the array without replicating the data because other ...
Homer512's user avatar
  • 15.1k
2 votes
2 answers
135 views

I want to tightly pack a structure, but have one specific member aligned to a particular boundary. For example: struct A { char a; int b; } __attribute__((packed)); struct B { char a; ...
Verly's user avatar
  • 21
0 votes
0 answers
71 views

Memory addresses must be aligned before they are used. I know that if they are not, performance costs more in CPU caching. I discovered that certain processors raise exceptions when unaligned memories ...
LEE LUNA's user avatar
3 votes
4 answers
231 views

It's a problem I ran into in my work. Our embedded platform is a customized Android OS running on quad-core Cortex-A7. Background: I'm receiving a set of parameters from outside my process, and it's ...
Nathan Weasley's user avatar
0 votes
0 answers
85 views

I'm creating a C++ allocator that should over-align the allocated memory by a runtime-determined alignment value. According to https://en.cppreference.com/w/cpp/memory/c/aligned_alloc, the std::...
tmlen's user avatar
  • 9,230
1 vote
0 answers
111 views

I am doing bare-metal development and interfacing a microcontroller with a SPI NOR flash chip for storing NVS key-value data. My NVS key-value struct takes up 160 bytes and looks like this: typedef ...
Engineer999's user avatar
  • 4,159
0 votes
2 answers
171 views

Let's just say you a have 32-bit integer, that integer needs to be aligned in memory on a four-byte boundary. Let's just say there's a byte buffer, and you want to store the bytes of that 32-bit ...
Zebrafish's user avatar
  • 16.3k
3 votes
1 answer
203 views

I am experimenting with malloc in C to better understand how memory alignment and allocation actually work behind the scenes. Here is the simple code I am running: #include <stdio.h> #include &...
Navid Fayezi's user avatar
1 vote
1 answer
143 views

Excerpt from the book "C++ memory management" by Patrice Roy For example, the following code is correct, albeit not something one should seek to do (it makes no sense, and it does things in ...
alex_noname's user avatar
  • 33.2k
-2 votes
1 answer
84 views

I upload a mip chain of BC1_RGB_UNORM_BLOCK to a staging buffer in host memory. Then I do buffer to image copy. And I get the error: Vulkan validation layer callback: vkCmdCopyBufferToImage(): ...
Zebrafish's user avatar
  • 16.3k
3 votes
1 answer
101 views

I was reading this article on the Internet regarding alignment PostgreSQL. Based on the example of the article and on some work experience I had with the alignment, I did a small experiment with the ...
Xocas17's user avatar
  • 51
7 votes
1 answer
139 views

I'm working on a 32-bit C++ application using MSVC with project settings /WX (treat warnings as errors) and /W4 (warning level 4). I've encountered a C4121 warning ("alignment of a member was ...
semicolon's user avatar
  • 135
3 votes
1 answer
174 views

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 ...
nh2's user avatar
  • 26k
0 votes
0 answers
48 views

I'm writing my ray tracing game engine in Swift and Metal on my Mac. So it is very necessary to make full use of the natural optimize of Metal. My current version can work, but it is incredibly slow ...
deepinFolk's user avatar
0 votes
0 answers
131 views

I am experiencing a weird bug in the function CopyAcceleratorTable when compiled for 64 bit (CopyAcceleratorTable). I have two accelerator tables (from two dlls) which I want to concatenate into a ...
pisoir's user avatar
  • 226
3 votes
2 answers
177 views

struct Node { Node *left; Node *right; int height; char data[]; }; This is how I used to define my data structure nodes, I find it very useful because I can embed the data directly in the ...
stefan's user avatar
  • 43
5 votes
2 answers
269 views

I made a really simple arena allocator in C and I was wondering one thing. Here is my header file (by the way if this api does not seems right please tell me!). #ifndef ARENA_H #define ARENA_H #...
user30097526's user avatar
4 votes
1 answer
201 views

I am using GCC 14.1 with C++17, and want to allocate 32 bytes-aligned memory always. #include <immintrin.h> #include <vector> int main() { std::vector<__m256> d; } g++ -std=c++...
JS0's user avatar
  • 99
3 votes
1 answer
183 views

I'm writing a C compiler as a hobby and would like it to be able to link against C static libraries produced by MSVC. I read the Microsoft x64 ABI, and it doesn't seem to have a strongly mandated ...
knutaf's user avatar
  • 113
2 votes
3 answers
112 views

I have this struct: typedef struct { int *array; int first; int last; } arguments; and I would be interested in having a different struct with some added arguments: typedef struct { ...
Tudor's user avatar
  • 157
1 vote
0 answers
44 views

If I do: .model tiny .code _start: mov [var1], ax .data? ALIGN 4 var1 dw ? var2 dw ? buf db 4096 dup(?) end I get Warning A4130: Incompatible with segment alignment: 4 If ...
Joshua's user avatar
  • 43.6k
0 votes
1 answer
120 views

I ran a test to better understand how pages affect performance when traversing & reading objects in memory but I got the opposite of what I was expecting. I'm hoping someone can explain this ...
greenlagoon's user avatar
1 vote
1 answer
457 views

I came across the following definition of max_align_t on cppreference.com: `max_align_t is a type whose alignment requirement is at least as strict (as large) as that of every scalar type. This ...
user51462's user avatar
  • 2,092
2 votes
1 answer
281 views

Background I have a struct with a flexible array member, which I am using to store arbitrarily-sized data inline (for a generic linked list for any element type), and I can simply cast data to T* to ...
Anon's user avatar
  • 381
0 votes
1 answer
72 views

I'm writing a simple program that encrypts a file by xor'ing its bytes with a given key. /* ... */ void encrypt_file_block( int fd, unsigned long *file_len, unsigned long curr_file_pos, ...
Fyodor's user avatar
  • 185
2 votes
0 answers
122 views

In HTSlib, Bonfield memory aligns a series of methods to 32. Why did he do this and what does it achieve? So, for example here there's this code: if (type == 'c') { if (!(q = ...
Marco's user avatar
  • 9,113
1 vote
0 answers
84 views

I was optimizing some C language codes and realized a weird thing. I noticed a piece of useless code (not being used by any parts) and deleted it. But the performance went down by around 4%, which is ...
Tall's user avatar
  • 123
0 votes
1 answer
101 views

i have a simple c function in start.c $ cat start.c int main(int,char**); void _start(){ char*v[2]={"k",0}; main(1,v); } when i compile to assembler, with clang -O -march=cannonlake -S ...
effbiae's user avatar
  • 1,167
2 votes
1 answer
231 views

I have the following struct with conversion logic: enum TagType { DOUBLE, BYTE, } impl TagType { /// byte-size actually fn size(&self) -> usize { match self { TagType::DOUBLE ...
Fee's user avatar
  • 870
0 votes
1 answer
77 views

I read a file, put the data into a buffer, say char array. After that I copy part of the data to a struct and increment an offset to read the next data part. The struct is like a header, whose member ...
Minh Pham's user avatar
  • 406
5 votes
1 answer
174 views

The following struct is 16 bytes on my setup: struct MyExampleStruct { double d; char b; }; Due to the rule that the size of a struct is rounded up to the minimum alignment of it's largest ...
Zebrafish's user avatar
  • 16.3k
1 vote
1 answer
74 views

I'm trying to compile the following test code below, that only writes the 32-bits variable into a pointer. I write it once as byte access, and second time as word access. void load_data_8(uint32_t ...
unalignedmemoryaccess's user avatar
1 vote
0 answers
183 views

I've been learning about memory alignment and have some doubts. In this stackoverflow post, there is a comment: new and malloc, by default, align address to 8 bytes (x86) or 16 bytes (x64), which is ...
NightFuryLxD's user avatar
2 votes
1 answer
103 views

It is said that data/instruction starting address should be a multiple of it's size and if it is so, we call it x-byte aligned where x is size of data/instruction in memory. Why it should be like this?...
Ayush Somani's user avatar
0 votes
1 answer
106 views

I'm currently reading "Embedded Systems with ARM Cortex-M Microcontrollers in Assembly Language and C" by Yifeng Zhu (Amazon link), and I'm stuck on a concept explained on page 88 regarding ...
user97662's user avatar
  • 980
2 votes
0 answers
123 views

I'm curious whether aligning performance-critical assembly functions to a 16-byte boundary is truly beneficial, or if it's just a micro-optimization that can be safely ignored nowadays? For example, ...
vengy's user avatar
  • 2,467
2 votes
1 answer
62 views

I crosscompile for cortex M microcontroller using arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi The .bss has 2KB alignment objdump: Idx Name Size VMA LMA File off ...
mastupristi's user avatar
  • 1,598
-1 votes
1 answer
125 views

My limited understanding of memory alignment in C++ is that structures are typically aligned to the strictest alignment requirement of any member. This means that size of a struct is always a multiple ...
Emre Tekmen's user avatar
3 votes
0 answers
94 views

I am using the PIC24FJ128GA306 microcontroller and trying to reserve a block in flash memory to store persistent data. Here is the code snippet I am using to define and allocate the persistent data: ...
user24822085's user avatar
0 votes
1 answer
103 views

I am writing a Boost.Interprocess code for shared memory between two processes. I am using managed_shared_memory. I'm initializing the memory using boost::interprocess::open_or_create, and I am ...
user avatar
6 votes
3 answers
636 views

I am writing a tool to port games written in C/C++ from the 24bit eZ80 to Windows/Linux. One of the issues is that int24_t doesn't exist on x86/x64. typedef uint32_t uint24_t doesn't always work, ...
Vortex 2728182818's user avatar
1 vote
1 answer
134 views

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 ...
glades's user avatar
  • 5,374
4 votes
0 answers
120 views

I have encountered what I believe to be an inconsistency using the alignas specifier in using declarations. Where any template will mess up the alignment. Based on the example provided in this ...
Miguel Veganzones's user avatar
2 votes
1 answer
608 views

I am writing an ELF parser as a side project and I have encountered a problem while trying to parse .note* sections. The documentation for ELF32 and ELF64 (available here and here, pages 42 and 13 ...
Ledmington's user avatar
5 votes
1 answer
319 views

in a software project of mine, on linux, I need to create a special section that needs to be populated with 40 bytes large structures. Then I would like to treat this section as an array. For that I ...
mastupristi's user avatar
  • 1,598
1 vote
1 answer
233 views

I've been banging my head against the wall for a while on this one. The context is that I'm trying to build an embedded VM for 8-bit AVR processors, but the question is not specific to the AVR. Here's ...
Niels Reijers's user avatar
2 votes
1 answer
95 views

Suppose such structs: A is out of our control but we can change the B structure: struct A { int64_t x; // 8 bytes int32_t y; // 4 bytes // 4 padding bytes }; struct B { A a; ...
Alexander S's user avatar

1
2 3 4 5
27