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
21-------------------------------------------------------------------------------
23-------------------------------------------------------------------------------
27import GHC.Base (realWorld#)
30-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
34{-# INLINE unsafeInlineIO #-}
35unsafeInlineIO :: IO a -> a
36unsafeInlineIO (IO m) = case m realWorld# of (# _, r #) -> r
38-- | Returns the heap allocation overhead for allocating a byte array. Each
39-- heap object contains a one word header. Byte arrays contain the size of the
40-- array after the header.
42-- See https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/rts/storage/heap-objects#arrays
44byteArrayOverhead :: Int
45byteArrayOverhead = 2 * SIZEOF_HSWORD
47-- | When we allocate a byte array of size @k@ the allocator actually allocates
48-- memory of size @k + byteArrayOverhead@. @arrayPayloadSize n@ returns the
49-- size of the array in bytes that would result in an allocation of @n@ bytes.
51arrayPayloadSize :: Int -> Int
52arrayPayloadSize n = let size = n - byteArrayOverhead in max size 0
54-- | Default maximum buffer size in bytes, for reading from and writing to IO
55-- devices, the value is 32KB minus GHC allocation overhead, which is a few
56-- bytes, so that the actual allocation is 32KB.
57defaultChunkSize :: Int
58defaultChunkSize = 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