ArrayAllocators.ArrayAllocatorsModule
ArrayAllocators

Defines an array allocator interface and concrete array allocators using malloc, calloc, and memory alignment.

Examples

using ArrayAllocators

Array{UInt8}(malloc, 100)
Array{UInt8}(calloc, 1024, 1024)
Array{UInt8}(MemAlign(2^16), (1024, 1024, 16))

See also NumaAllocators, SafeByteCalculators

ArrayAllocators.AbstractArrayAllocatorType
AbstractArrayAllocator{B}

Parent abstract type for array allocators. Parameter B is an AbstractByteCalculator Defines Array{T}(allocator, dims...) where T = Array{T}(allocator, dims)

ArrayAllocators.CallocAllocatorType
CallocAllocator()

Use Libc.calloc to allocate an array. This is similar to zeros, except that the Libc implementation or the operating system may allocate and zero the memory in a lazy fashion.

See also https://en.cppreference.com/w/c/memory/calloc .

ArrayAllocators.MallocAllocatorType
MallocAllocator()

Allocate array using Libc.malloc. This is not meant to be useful but rather just to prototype the concept for a custom array allocator concept. This should be similar to using undef.

See also https://en.cppreference.com/w/c/memory/malloc .

ArrayAllocators.MemAlignType
MemAlign([alignment::Integer])

Allocate aligned memory. Alias for platform specific implementations.

alignment must be a power of 2.

On POSIX systems, alignment must be a multiple of sizeof(Ptr). On Windows, alignment must be a multiple of 2^16.

If alignment is not specified, it will be set to min_alignment(MemAlign).

MemAlign is a constant alias for one the following platform specific implementations.

ArrayAllocators.alignmentMethod
alignment(alloc::AbstractMemAlign)

Get byte alignment of the AbstractMemAlign array allocator.

ArrayAllocators.wrap_libc_pointerMethod
wrap_libc_pointer(::Type{A}, ptr::Ptr{T}, dims) where {T, A <: AbstractArray{T}}
wrap_libc_pointer(ptr::Ptr{T}, dims) where {T, A <: AbstractArray{T}}

Checks to see if ptr is C_NULL for an OutOfMemoryError. Owns the array such that Libc.free is used.

ArrayAllocators.zerosMethod
ArrayAllocators.zeros(T=Float64, dims::Integer...)
ArrayAllocators.zeros(T=Float64, dims::Dims)

Return an Array with element type T with size dims filled by 0s via calloc. Depending on the libc implementation, the operating system may lazily wait for a page fault before obtaining memory initialized to 0. This is an alternative to Base.zeros that always fills the array with 0 eagerly.

Examples

julia> @time ArrayAllocators.zeros(Int, 3200, 3200);
  0.000026 seconds (4 allocations: 78.125 MiB)

julia> @time Base.zeros(Int, 3200, 3200);
  0.133595 seconds (2 allocations: 78.125 MiB, 67.36% gc time)
 
julia> ArrayAllocators.zeros(Int, 256, 256) == Base.zeros(Int, 256, 256)
true