1{-# LANGUAGE UnboxedTuples #-}
4-- Module : Streamly.Internal.System.IO
5-- Copyright : (c) 2020 Composewell Technologies
6-- License : BSD-3-Clause
7-- Maintainer : streamly@composewell.com
8-- Stability : experimental
12module Streamly.Internal.System.IO
20-------------------------------------------------------------------------------
22-------------------------------------------------------------------------------
24import Foreign.Storable (Storable(sizeOf))
25import GHC.Base (realWorld#)
28-------------------------------------------------------------------------------
30-------------------------------------------------------------------------------
32{-# INLINE unsafeInlineIO #-}
33unsafeInlineIO :: IO a -> a
34unsafeInlineIO (IO m) = case m realWorld# of (# _, r #) -> r
36-- | Returns the heap allocation overhead for allocating a byte array. Each
37-- heap object contains a one word header. Byte arrays contain the size of the
38-- array after the header.
40-- See https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/rts/storage/heap-objects#arrays
42byteArrayOverhead :: Int
43byteArrayOverhead = 2 * sizeOf (undefined :: Word)
45-- | When we allocate a byte array of size @k@ the allocator actually allocates
46-- memory of size @k + byteArrayOverhead@. @arrayPayloadSize n@ returns the
47-- size of the array in bytes that would result in an allocation of @n@ bytes.
49arrayPayloadSize :: Int -> Int
50arrayPayloadSize n = let size = n - byteArrayOverhead in max size 0
52-- | Default maximum buffer size in bytes, for reading from and writing to IO
53-- devices, the value is 32KB minus GHC allocation overhead, which is a few
54-- bytes, so that the actual allocation is 32KB.
55defaultChunkSize :: Int
56defaultChunkSize = arrayPayloadSize (32 * 1024)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list