blob: e1de9a6a8929910ff2ae9658de517f6bef32e094 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
{-# LANGUAGE MagicHash, UnboxedTuples #-}
import GHC.Compact
import GHC.Int
import GHC.Exts
import GHC.IO
import GHC.Exts
data BA = ByteArray ByteArray#
newByteArray :: Int -> IO BA
newByteArray (I# sz) = IO $ \s -> case newByteArray# sz s of {
(# s', arr# #) -> case unsafeFreezeByteArray# arr# s of {
(# s'', barr# #) -> (# s', ByteArray barr# #) }}
-- Currently we expect large/compact regions not to count as pinned.
-- See #22255 for the reasoning.
main :: IO ()
main = do
ByteArray arr1# <- fmap getCompact $ newByteArray 65000 >>= compact
ByteArray arr2# <- newByteArray 65000
print (I# (isByteArrayPinned# arr1#))
print (I# (isByteArrayPinned# arr2#))
putStrLn "Finished"
|