memalignandmemalign_clearallocate alignedVector{T}storage, either uninitialised or zeroed.memalignedandmemaligned_clearreshape aligned buffers into multi-dimensional arrays without copying.memalign_fixedandmemalign_clear_fixedbuild alignedFixedSizeArrays.jlcontainers directly.alignment(::AbstractArray)reports the effective pointer alignment at runtime.- Cache-line detection with a safe fallback keeps defaults portable across platforms.
- Precompilation via
PrecompileToolsminimises package load time.
pkg> add AlignedAllocsJulia 1.11 or newer is required.
julia> using AlignedAllocs
# Cache-line aligned Float32 buffer
julia> xs = memalign(Float32, 256)
256-element Vector{Float32}:
0.0
0.0
#= output truncated =#
# Explicit alignment with zero-initialisation
julia> ys = memalign_clear(UInt16, 128, 256)
# Multi-dimensional array with aligned storage
julia> az = memaligned(Float32, 32, 8; align=128)
32x8 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
#= output truncated =#
# Fixed-size array backed by aligned storage
julia> using FixedSizeArrays
julia> fs = memalign_fixed(Float32, 16, 4; align=128)
16x4 FixedSizeArrays.FixedSizeMatrix{Float32}:
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
#= output truncated =#
# Inspect alignment guarantee
julia> alignment(az)
128See the User Guide for workflow examples and the API Reference for detailed signatures.
- Alignments must be powers of two >= 16 bytes; invalid inputs throw
ArgumentError. - On POSIX systems vectors own the memory returned by
posix_memalign. - On Windows vectors register a finalizer that calls
_aligned_freewhen the array is collected. memalign_clearpreserves the vector while zeroing memory viaBase.memset.
Run the test suite with:
julia --project=. -e "using Pkg; Pkg.test()"Documentation is built with Documenter.jl. See docs/ for build scripts and source pages.
MIT License (c) 2025 Jeffrey Sarnoff.