Skip to content

Instantly share code, notes, and snippets.

@s9gf4ult
Created June 26, 2013 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s9gf4ult/5866034 to your computer and use it in GitHub Desktop.
Save s9gf4ult/5866034 to your computer and use it in GitHub Desktop.
15:20 razor@localhost /home/razor % cat ./yoba.hs
{-# LANGUAGE ScopedTypeVariables, TypeFamilies #-}
module VV where
import Control.Monad
import Foreign.ForeignPtr.Safe
import Foreign.Storable
import System.IO
import System.Environment
import qualified Data.Vector.Storable as U
import Data.Word
loadVector :: forall a. (Num a, Storable a) => String -> IO (U.Vector a)
loadVector name =
withFile name ReadMode $ \h -> do
len <- liftM fromIntegral $ hFileSize h
ptr <- mallocForeignPtrBytes len
_ <- withForeignPtr ptr $ \p -> hGetBuf h p len
return $ U.unsafeFromForeignPtr0 ptr (len `div` sizeOf (0 :: a))
main = do
args <- getArgs
case args of
[file] -> do
(v :: U.Vector Word8) <- loadVector file
print $ v U.! 1
_ -> putStrLn "fuck you"
15:20 razor@localhost /home/razor % ghc -main-is VV yoba.hs
[1 of 1] Compiling VV ( yoba.hs, yoba.o )
Linking yoba ...
15:21 razor@localhost /home/razor % du -hs WinXPSP3_11_03_2011.iso
657M WinXPSP3_11_03_2011.iso
15:21 razor@localhost /home/razor % time ./yoba WinXPSP3_11_03_2011.iso
0
./yoba WinXPSP3_11_03_2011.iso 0,00s user 0,42s system 97% cpu 0,431 tota
# Если че, файл уже был в кеше
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment