Memory alignment
NumPy alignment goals
There are three use-cases related to memory alignment in NumPy (as of 1.14):
Creating structured datatypes with fields aligned like in a C-struct.
Speeding up copy operations by using
uintassignment in instead ofmemcpy.Guaranteeing safe aligned access for ufuncs/setitem/casting code.
NumPy uses two different forms of alignment to achieve these goals: “True alignment” and “Uint alignment”.
“True” alignment refers to the architecture-dependent alignment of an equivalent C-type in C. For example, in x64 systems is equivalent to in C. On most systems, this has either an alignment of 4 or 8 bytes (and this can be controlled in GCC by the option ). A variable is aligned in memory if its memory offset is a multiple of its alignment. On some systems (eg. sparc) memory alignment is required; on others, it gives a speedup.