到文件以下程序不不爆炸時可執行(經由ghc -O0 Explode.hs
編譯)運行時,但確實爆炸在ghci中運行時(通過任一ghci Explode.hs
或ghci -fobject-code Explode.hs
):存儲器爆炸時寫入懶惰字節串中ghci中
--Explode.hs
--Does not explode with : ghc -O0 Explode.hs
--Explodes with : ghci Explode.hs
--Explodes with : ghci -fobject-code Explode.hs
module Main (main) where
import Data.Int
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as BLC
createStr :: Int64 -> String -> BL.ByteString
createStr num str = BL.take num $ BL.cycle $ BLC.pack str
main = do
BLC.writeFile "results.txt" $ createStr 100000000 "abc\n"
它爲什麼會爆炸在ghci中,不與ghc -O0 Explode.hs
,我怎麼能阻止它在ghci中爆炸?我在Memory blowing up for strict sum/strict foldl in ghci中採用的方法似乎在這裏工作。謝謝。
您可以留下' - O0':['-O0'如果不與另一個'-O *'標誌一起使用,實際上會被忽略](https://www.haskell.org/ghc/docs/latest/html/users_guide/options-optimise.html) 。 – Zeta