# CFFI.Memory

Machinery for interfacing with C.

(~~>) : Composite -> (CPtr -> IO ()) -> IO ()

  Perform an IO action with memory that is freed afterwards

  Fixity
    Left associative, precedence 1
withAlloc : Composite -> (CPtr -> IO a) -> IO a

  Perform an IO action with memory that is freed afterwards

update : (t : CType) -> CPtr -> (translate t -> translate t) -> IO ()

  Update memory with a function.

toPtr : CPtr -> Ptr
toCPtr : Ptr -> CPtr
poke : (t : CType) -> CPtr -> translate t -> IO ()

  Write to memory

peek : (t : CType) -> CPtr -> IO (translate t)

  Read from memory

mfree : Ptr -> IO ()

  Import of free from the C standard library.

malloc : Int -> IO Ptr

  Import of malloc from the C standard library.

free : CPtr -> IO ()

  Free memory allocated with alloc

field : Composite -> Nat -> CPtr -> CPtr

  Get a pointer to a field in a composite value

calloc : Int -> Int -> IO Ptr

  Import of calloc from the C standard library.

alloc : Composite -> IO CPtr

  Allocate enough memory to hold an instance of a C typr

data CPtr : Type
  CPt : Ptr -> Int -> CPtr
(#) : Composite -> Nat -> CPtr -> CPtr

  Get a pointer to a field in a composite value

  Fixity
    Left associative, precedence 10