HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulememory-0.18.0Haskell2010

Data.ByteArray

Simple and efficient byte array types

This module should be imported qualified.

  • 4 types
  • 2 classes
  • 34 values
  • Packagememory-0.18.0
  • Exports40
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceByteArray.hs

ByteArray Classes

2 declarations
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

7 declarations
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
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

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

ByteArray methods

31 declarations
valuetake :: ByteArray bs => Int -> bs -> bs
#

Take the first n byte of a bytearray

valuedrop :: ByteArray bs => Int -> bs -> bs
#

drop the first n byte of a bytearray

valuespan :: ByteArray bs => (Word8 -> Bool) -> bs -> (bs, bs)
#

Split a bytearray at the point where pred becomes invalid

valuesplitAt :: ByteArray bs => Int -> bs -> (bs, bs)
#

Split a bytearray at a specific length in two bytearray

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

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

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

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

valueindex :: ByteArrayAccess a => a -> Int -> Word8
#

return a specific byte indexed by a number from 0 in a bytearray

unsafe, no bound checking are done

valueappend :: ByteArray bs => bs -> bs -> bs
#

append one bytearray to the other

valuezero :: ByteArray ba => Int -> ba
#

Create a bytearray of a specific size initialized to 0

valueuncons :: ByteArray a => a -> Maybe (Word8, a)
#

returns the first byte, and the remaining bytearray if the bytearray is not null

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.

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.