Logo

Programming-Idioms

  • Fortran
  • Haskell

Idiom #88 Allocate 1M bytes

Create a new bytes buffer buf of size 1,000,000.

import Data.Vector.Unboxed.Mutable as V
import Data.Word                        (Word8)
createBuf :: Int -> IO (V.IOVector Word8)
createBuf n = V.new n

main :: IO ()
main = do
  buf <- createBuf 1000000
  return ()
  use iso_c_binding, only : c_int8_t
  integer(kind=c_int8_t), dimension(:), allocatable :: a

  allocate (a(10**6))
type Byte is range 0 .. 255
  with Size => 8;
      
type Byte_Array is array (Positive range <>) of Byte;  
      
Buf : Byte_Array (1 .. 1_000_000);

New implementation...
< >
programming-idioms.org