3 ms·
You don't need to know anything about alignment to write normal safe C code. Only when to dive deep into performance optimization you start to worry about those
by bluecalm 8y ago
You don't need to know anything about alignment to write normal safe C code. Only when to dive deep into performance optimization you start to worry about those things but hopefully by then you care enough to make sure to check what the language spec allows.
Seriously, just don't cast object of one type to another type and you can forget about alignment until you need to optimize.
- MaulingMonkey 8y agoCompiler generated SSE, and multithreading primitives, etc. will break on unaligned access even on relatively unalignment-tolerant x86 chips - to say nothing of stricter ARM CPUs. You need to keep this in mind basically any time you're going from byte buffers to more complicated types. Basically anything touching allocation or IO needs to be aware of it, IMO, even before optimization.