FixedSizeVectors offer a first, more performant and cleaner approach to working with (generally, numeric) vectors where, once formed, the size of the vector does not change.
AlignedAllocs provides cache-aligned memory as a Vector{T} where T is a given bitstype:
using FixedSizeArrays
using AlignedAllocs: memalign_clear, alignment
# memalign_clear zeros the memory block
# also exports `memalign` for a memory block of type T that is uninitialized.
# alignment(xs::AbstractVector) provides the byte alignment of the initial element of xs
# and so the byte alignment of the vector
element_type = Float32
element_count = 8
cache_aligned_mem = memalign_clear(element_type, element_count)
fixed_length_mem = FixedSizeVectorDefault{element_type}(undef, element_count)
alignment(cache_aligned_mem) >= 64
alignment(fixed_length_mem) >= 32 # for vectors with fewer than 2^9 elements
# on my machine
Working with cache-line-size aligned vectors is more perfomant generally and prevents the possible time hijacking of cache-line crossing data where it need not cross cache lines.
Most current pcs have a cache-line-size of 64 bytes (there are exceptions).
When using SIMD operations, aligning to 256 or 512 bytes (processor dependant) is very important to the performance of SIMD driven algorithms.
cache_aligned_mem = memalign_clear(element_type, element_count, 256)
alignment(cache_aligned_mem) >= 256
It would be great to obtain a FixedLengthVector backed by cache-aligned memory.