heph-aligned-storable-0.1.0.0: Generically derive Storable instances suitable for CPU-GPU transfer
Copyright(c) Jeremy Nuttall 2025
LicenseBSD-3-Clause
Maintainerjeremy@jeremy-nuttall.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Foreign.GPU.Marshal.Aligned

Description

Allocation helpers with guaranteed zero-initialized padding. Use these instead of alloca or malloc to avoid garbage in padding bytes.

Synopsis

Utilities for Packed values

type PackedPtr (layout :: MemoryLayout) a = AlignedPtr layout (Packed layout a) Source #

Convenience type for Packed AlignedPtr

withPacked :: forall (layout :: MemoryLayout) a m b. (MonadUnliftIO m, AlignedStorable layout a) => a -> (PackedPtr layout a -> m b) -> m b Source #

Temporarily allocates a zero-initialized block of memory and pokes a Packed value into it, providing a pointer to the result. The storage is freed automatically. The pointer is only valid within the continuation.

allocaPacked :: forall (layout :: MemoryLayout) a b m. (MonadUnliftIO m, AlignedStorable layout a) => (PackedPtr layout a -> m b) -> m b Source #

Allocates temporary, zero-initialized storage for a Packed value on the stack. The pointer is only valid within the continuation.

Utilities for Strided values

type StridedPtr (layout :: MemoryLayout) a = AlignedPtr layout (Strided layout a) Source #

Convenience type for Strided AlignedPtr

withStrided :: forall m (layout :: MemoryLayout) a b. (MonadUnliftIO m, AlignedStorable layout a) => a -> (StridedPtr layout a -> m b) -> m b Source #

Temporarily allocates a zero-initialized block of memory and pokes a Strided value into it, providing a pointer to the result. The storage is freed automatically. The pointer is only valid within the continuation.

allocaStrided :: forall m (layout :: MemoryLayout) a b. (MonadUnliftIO m, AlignedStorable layout a) => (StridedPtr layout a -> m b) -> m b Source #

Allocates temporary, zero-initialized storage for a Strided value on the stack. The pointer is only valid within the continuation.

Utilities for runtime length arrays

alignedCopyVector :: forall (layout :: MemoryLayout) a m. (MonadIO m, AlignedStorable layout a) => AlignedPtr layout a -> Vector (Strided layout a) -> m () Source #

Performs a straight copyBytes on the underlying pointer of Vector