Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 与RTSStats的分配不一致_Haskell_Ghc - Fatal编程技术网

Haskell 与RTSStats的分配不一致

Haskell 与RTSStats的分配不一致,haskell,ghc,Haskell,Ghc,我正在测量函数分配,我遇到了一些我不太理解的行为。下面是它的简单复制: module Main where import GHC.Stats (GCDetails(..), RTSStats(..), getRTSStats) import System.Mem (performGC) main :: IO () main = loop 100 where loop 0 = return () loop n = runOtherThing n >> loop

我正在测量函数分配,我遇到了一些我不太理解的行为。下面是它的简单复制:

module Main where

import GHC.Stats (GCDetails(..), RTSStats(..), getRTSStats)
import System.Mem (performGC)

main :: IO ()
main = loop 100
  where
    loop 0 = return ()
    loop n = runOtherThing n >> loop (n-1)

runOtherThing :: Int -> IO ()
runOtherThing n = do
    performGC
    stats <- getRTSStats
    putStrLn $ show (n `mod` 15) ++ ": "
            ++ show (gcdetails_allocated_bytes (gc stats))
            ++ " num: " ++ show (gcs stats)
    --putStrLn "inflate allocation"
我正在使用8.2.1和新的ish
RTSStats
,但它也适用于旧的
GCStats

每15个GC分配一个额外的~4k字节(可能是一页?)。左边的数字是循环编号
mod
15,因此您不必计数,只需在我的输出中查找以
9
开头的行即可。右边是程序执行的GC的总数,这表明我们没有丢失任何数据

我做了很多改变,数字总是精确到15。您可以取消对
充气分配
行的注释,该行按其说明操作。仍会报告额外的4k字节。即使您添加了多条线来扩大分配,它也不会改变

这让我相信额外的字节与我的代码无关。或者至少,不是我分配数据触发的

我真的不知道该怎么看。为了测量分配,我可能会制定一个合理的策略来检测和删除这些数据点。但有可能完全避免这种情况吗?15点是多少

$ ghc Main.hs
$ ./Main +RTS -s
...
14: 4648 num: 12
13: 4744 num: 13
12: 4744 num: 14
11: 4744 num: 15
10: 4744 num: 16
9: 8704 num: 17
8: 4648 num: 18
7: 4648 num: 19
6: 4648 num: 20
5: 4648 num: 21
4: 4648 num: 22
3: 4648 num: 23
2: 4648 num: 24
1: 4648 num: 25
0: 4648 num: 26
14: 4648 num: 27
13: 4744 num: 28
12: 4744 num: 29
11: 4744 num: 30
10: 4744 num: 31
9: 8704 num: 32
8: 4648 num: 33
7: 4648 num: 34
6: 4648 num: 35
5: 4648 num: 36
4: 4648 num: 37
3: 4648 num: 38
2: 4648 num: 39
1: 4648 num: 40
0: 4648 num: 41
...