blob: 3d815fcd1c15abefadd894e5dc2411b169e760d4 (
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
-- Test the function of the isPinnedByteArray# primop
import GHC.Exts
import GHC.IO
main :: IO ()
main = do
-- Unpinned MutableByteArray
r <- IO $ \s0 ->
case newByteArray# 1024# s0 of
(# s1, mba #) ->
(# s1, isTrue# (isMutableByteArrayPinned# mba) #)
print r
-- Pinned MutableByteArray
r <- IO $ \s0 ->
case newPinnedByteArray# 1024# s0 of
(# s1, mba #) ->
(# s1, isTrue# (isMutableByteArrayPinned# mba) #)
print r
-- Pinned, Aligned MutableByteArray
r <- IO $ \s0 ->
case newAlignedPinnedByteArray# 1024# 16# s0 of
(# s1, mba #) ->
(# s1, isTrue# (isMutableByteArrayPinned# mba) #)
print r
-- Unpinned ByteArray
r <- IO $ \s0 ->
case newByteArray# 1024# s0 of
(# s1, mba #) ->
case unsafeFreezeByteArray# mba s1 of
(# s2, ba #) ->
(# s2, isTrue# (isByteArrayPinned# ba) #)
print r
-- Pinned ByteArray
r <- IO $ \s0 ->
case newPinnedByteArray# 1024# s0 of
(# s1, mba #) ->
case unsafeFreezeByteArray# mba s1 of
(# s2, ba #) ->
(# s2, isTrue# (isByteArrayPinned# ba) #)
print r
|