HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulememory-0.18.0Haskell2010

Data.ByteArray

Simple and efficient byte array types

This module should be imported qualified.

Contents
  1. ByteArray Classes
  2. ByteArray built-in types
  3. ByteArray methods
Synopsis
  • Packagememory-0.18.0
  • Exports40
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceByteArray.hs

ByteArray Classes

classclass (Eq ba, Ord ba, Monoid ba, ByteArrayAccess ba) => ByteArray ba where

Class to allocate new ByteArray of specific size

Methods

  • allocRet :: Int -> (Ptr p -> IO a) -> IO (a, ba)

    allocate n bytes and perform the given operation

Instances5ByteArray
classclass ByteArrayAccess ba where

Class to Access size properties and data of a ByteArray

Methods

Instances10ByteArrayAccess, …

ByteArray built-in types

datadata Bytes

Simplest Byte Array

Instances9Eq, Ord, Show, Semigroup, Monoid, NFData, …
  • Eq BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • Ord BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • Show BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • Semigroup BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • Monoid BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • NFData BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • NormalForm BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • ByteArray BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
  • ByteArrayAccess BytesDefined in memory-0.18.0 · Data.ByteArray.Bytes
datadata ScrubbedBytes

ScrubbedBytes is a memory chunk which have the properties of:

  • Being scrubbed after its goes out of scope.

  • A Show instance that doesn't actually show any content

  • A Eq instance that is constant time

Instances10Eq, Ord, Show, IsString, Semigroup, Monoid, …
datadata MemView

A simple abstraction to a piece of memory.

Do beware that garbage collection related to piece of memory could be triggered before this is used.

Only use with the appropriate handler has been used (e.g. withForeignPtr on ForeignPtr)

Constructors

Instances3Eq, Show, ByteArrayAccess
valuedropView
  1. :: ByteArrayAccess bytes
  2. => bytes

    byte array

  3. -> Int

    the number of bytes do dropped before creating the view

  4. -> View bytes

create a view from the given byte array starting after having dropped the fist n bytes

valueview
  1. :: ByteArrayAccess bytes
  2. => bytes

    the byte array we put a view on

  3. -> Int

    the offset to start the byte array on

  4. -> Int

    the size of the view

  5. -> View bytes

create a view on a given bytearray

This function update the offset and the size in order to guarantee:

  • offset >= 0

  • size >= 0

  • offset < length

  • size =< length - offset

ByteArray methods

valuealloc :: ByteArray ba => Int -> (Ptr p -> IO ()) -> IO ba

Allocate a new bytearray of specific size, and run the initializer on this memory

valueconstEq :: (ByteArrayAccess bs1, ByteArrayAccess bs2) => bs1 -> bs2 -> Bool

A constant time equality test for 2 ByteArrayAccess values.

If values are of 2 different sizes, the function will abort early without comparing any bytes.

compared to == , this function will go over all the bytes present before yielding a result even when knowing the overall result early in the processing.

valueeq :: (ByteArrayAccess bs1, ByteArrayAccess bs2) => bs1 -> bs2 -> Bool

Check if two bytearray are equals

This is not constant time, as soon some byte differs the function will returns. use constEq in sensitive context where timing matters.