Copyright | (c) Mateusz Kłoczko, 2016 |
---|---|
License | MIT |
Maintainer | mateusz.p.kloczko@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Documentation
class GStorable a where Source #
The class uses the default Generic based implementations to provide Storable instances for types made from primitive types. Does not work on Algebraic Data Types with more than one constructor.
Calculate the size of the type.
gsizeOf :: (Generic a, GStorable' (Rep a)) => a -> Int Source #
Calculate the size of the type.
galignment :: a -> Int Source #
Calculate the alignment of the type.
galignment :: (Generic a, GStorable' (Rep a)) => a -> Int Source #
Calculate the alignment of the type.
gpeekByteOff :: Ptr b -> Int -> IO a Source #
Read the variable from a given pointer.
gpeekByteOff :: (Generic a, GStorable' (Rep a)) => Ptr b -> Int -> IO a Source #
Read the variable from a given pointer.
gpokeByteOff :: Ptr b -> Int -> a -> IO () Source #
Write the variable to a pointer.
gpokeByteOff :: (Generic a, GStorable' (Rep a)) => Ptr b -> Int -> a -> IO () Source #
Write the variable to a pointer.
The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.
Memory addresses are represented as values of type
, for some
Ptr
aa
which is an instance of class Storable
. The type argument to
Ptr
helps provide some valuable type safety in FFI code (you can't
mix pointers of different types without an explicit cast), while
helping the Haskell type system figure out which marshalling method is
needed for a given pointer.
All marshalling between Haskell and a foreign language ultimately
boils down to translating Haskell data structures into the binary
representation of a corresponding data structure of the foreign
language and vice versa. To code this marshalling in Haskell, it is
necessary to manipulate primitive data types stored in unstructured
memory blocks. The class Storable
facilitates this manipulation on
all types for which it is instantiated, which are the standard basic
types of Haskell, the fixed size Int
types (Int8
, Int16
,
Int32
, Int64
), the fixed size Word
types (Word8
, Word16
,
Word32
, Word64
), StablePtr
, all types from Foreign.C.Types,
as well as Ptr
.
sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)