Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- data Ptr a
- nullPtr :: Ptr a
- castPtr :: Ptr a -> Ptr b
- plusPtr :: Ptr a -> Int -> Ptr b
- alignPtr :: Ptr a -> Int -> Ptr a
- minusPtr :: Ptr a -> Ptr b -> Int
- alloca :: Storable a => (Ptr a -> IO b) -> IO b
- allocaBytes :: Int -> (Ptr a -> IO b) -> IO b
- allocaBytesAligned :: Int -> Int -> (Ptr a -> IO b) -> IO b
- malloc :: Storable a => IO (Ptr a)
- mallocBytes :: Int -> IO (Ptr a)
- calloc :: Storable a => IO (Ptr a)
- callocBytes :: Int -> IO (Ptr a)
- realloc :: Storable b => Ptr a -> IO (Ptr b)
- reallocBytes :: Ptr a -> Int -> IO (Ptr a)
- copyBytes :: Ptr a -> Ptr a -> Int -> IO ()
- moveBytes :: Ptr a -> Ptr a -> Int -> IO ()
- fillBytes :: Ptr a -> Word8 -> Int -> IO ()
- free :: Ptr a -> IO ()
- mallocArray :: Storable a => Int -> IO (Ptr a)
- mallocArray0 :: Storable a => Int -> IO (Ptr a)
- allocaArray :: Storable a => Int -> (Ptr a -> IO b) -> IO b
- allocaArray0 :: Storable a => Int -> (Ptr a -> IO b) -> IO b
- reallocArray :: Storable a => Ptr a -> Int -> IO (Ptr a)
- reallocArray0 :: Storable a => Ptr a -> Int -> IO (Ptr a)
- callocArray :: Storable a => Int -> IO (Ptr a)
- callocArray0 :: Storable a => Int -> IO (Ptr a)
- peekArray :: Storable a => Int -> Ptr a -> IO [a]
- peekArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO [a]
- pokeArray :: Storable a => Ptr a -> [a] -> IO ()
- pokeArray0 :: Storable a => a -> Ptr a -> [a] -> IO ()
- newArray :: Storable a => [a] -> IO (Ptr a)
- newArray0 :: Storable a => a -> [a] -> IO (Ptr a)
- withArray :: Storable a => [a] -> (Ptr a -> IO b) -> IO b
- withArray0 :: Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
- withArrayLen :: Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
- withArrayLen0 :: Storable a => a -> [a] -> (Int -> Ptr a -> IO b) -> IO b
- copyArray :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
- moveArray :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
- lengthArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO Int
- advancePtr :: Storable a => Ptr a -> Int -> Ptr a
- data Pool
- newPool :: IO Pool
- freePool :: Pool -> IO ()
- withPool :: (Pool -> IO b) -> IO b
- pooledMalloc :: Storable a => Pool -> IO (Ptr a)
- pooledMallocBytes :: Pool -> Int -> IO (Ptr a)
- pooledRealloc :: Storable a => Pool -> Ptr a -> IO (Ptr a)
- pooledReallocBytes :: Pool -> Ptr a -> Int -> IO (Ptr a)
- pooledMallocArray :: Storable a => Pool -> Int -> IO (Ptr a)
- pooledMallocArray0 :: Storable a => Pool -> Int -> IO (Ptr a)
- pooledReallocArray :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
- pooledReallocArray0 :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
- pooledNew :: Storable a => Pool -> a -> IO (Ptr a)
- pooledNewArray :: Storable a => Pool -> [a] -> IO (Ptr a)
- pooledNewArray0 :: Storable a => Pool -> a -> [a] -> IO (Ptr a)
- newtype IntPtr = IntPtr Int
- ptrToIntPtr :: Ptr a -> IntPtr
- intPtrToPtr :: IntPtr -> Ptr a
- newtype WordPtr = WordPtr Word
- ptrToWordPtr :: Ptr a -> WordPtr
- wordPtrToPtr :: WordPtr -> Ptr a
Documentation
A value of type
represents a pointer to an object, or an
array of objects, which may be marshalled to or from Haskell values
of type Ptr
aa
.
The type a
will often be an instance of class
Storable
which provides the marshalling operations.
However this is not essential, and you can provide your own operations
to access the pointer. For example you might write small foreign
functions to get or set the fields of a C struct
.
Instances
NFData1 Ptr | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
GEq1 v (UAddr :: * -> *) | |
GOrd1 v (UAddr :: * -> *) | |
Defined in Data.Functor.Classes.Generic.Internal | |
Generic1 (URec (Ptr ()) :: k -> *) | |
Eq (Ptr a) | |
Data a => Data (Ptr a) | Since: base-4.8.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ptr a -> c (Ptr a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ptr a) # dataTypeOf :: Ptr a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Ptr a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ptr a)) # gmapT :: (forall b. Data b => b -> b) -> Ptr a -> Ptr a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ptr a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ptr a -> r # gmapQ :: (forall d. Data d => d -> u) -> Ptr a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ptr a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ptr a -> m (Ptr a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ptr a -> m (Ptr a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ptr a -> m (Ptr a) # | |
Ord (Ptr a) | |
Show (Ptr a) | Since: base-2.1 |
Hashable (Ptr a) | |
Defined in Data.Hashable.Class | |
Storable (Ptr a) | Since: base-2.1 |
NFData (Ptr a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
Prim (Ptr a) | |
Defined in Data.Primitive.Types alignment# :: Ptr a -> Int# # indexByteArray# :: ByteArray# -> Int# -> Ptr a # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, Ptr a#) # writeByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> Ptr a -> State# s -> State# s # indexOffAddr# :: Addr# -> Int# -> Ptr a # readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, Ptr a#) # writeOffAddr# :: Addr# -> Int# -> Ptr a -> State# s -> State# s # setOffAddr# :: Addr# -> Int# -> Int# -> Ptr a -> State# s -> State# s # | |
Functor (URec (Ptr ()) :: * -> *) | |
Foldable (URec (Ptr ()) :: * -> *) | |
Defined in Data.Foldable fold :: Monoid m => URec (Ptr ()) m -> m # foldMap :: Monoid m => (a -> m) -> URec (Ptr ()) a -> m # foldr :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b # foldr' :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b # foldl :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b # foldl' :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b # foldr1 :: (a -> a -> a) -> URec (Ptr ()) a -> a # foldl1 :: (a -> a -> a) -> URec (Ptr ()) a -> a # toList :: URec (Ptr ()) a -> [a] # null :: URec (Ptr ()) a -> Bool # length :: URec (Ptr ()) a -> Int # elem :: Eq a => a -> URec (Ptr ()) a -> Bool # maximum :: Ord a => URec (Ptr ()) a -> a # minimum :: Ord a => URec (Ptr ()) a -> a # | |
Traversable (URec (Ptr ()) :: * -> *) | |
Defined in Data.Traversable | |
Eq (URec (Ptr ()) p) | |
Ord (URec (Ptr ()) p) | |
Defined in GHC.Generics compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # | |
Generic (URec (Ptr ()) p) | |
data URec (Ptr ()) (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
type Rep1 (URec (Ptr ()) :: k -> *) | |
Defined in GHC.Generics | |
type Rep (URec (Ptr ()) p) | |
Defined in GHC.Generics |
alignPtr :: Ptr a -> Int -> Ptr a #
Given an arbitrary address and an alignment constraint,
alignPtr
yields the next higher address that fulfills the
alignment constraint. An alignment constraint x
is fulfilled by
any address divisible by x
. This operation is idempotent.
minusPtr :: Ptr a -> Ptr b -> Int #
Computes the offset required to get from the second to the first argument. We have
p2 == p1 `plusPtr` (p2 `minusPtr` p1)
alloca :: Storable a => (Ptr a -> IO b) -> IO b #
executes the computation alloca
ff
, passing as argument
a pointer to a temporarily allocated block of memory sufficient to
hold values of type a
.
The memory is freed when f
terminates (either normally or via an
exception), so the pointer passed to f
must not be used after this.
allocaBytes :: Int -> (Ptr a -> IO b) -> IO b #
executes the computation allocaBytes
n ff
, passing as argument
a pointer to a temporarily allocated block of memory of n
bytes.
The block of memory is sufficiently aligned for any of the basic
foreign types that fits into a memory block of the allocated size.
The memory is freed when f
terminates (either normally or via an
exception), so the pointer passed to f
must not be used after this.
malloc :: Storable a => IO (Ptr a) #
Allocate a block of memory that is sufficient to hold values of type
a
. The size of the area allocated is determined by the sizeOf
method from the instance of Storable
for the appropriate type.
The memory may be deallocated using free
or finalizerFree
when
no longer required.
mallocBytes :: Int -> IO (Ptr a) #
Allocate a block of memory of the given number of bytes. The block of memory is sufficiently aligned for any of the basic foreign types that fits into a memory block of the allocated size.
The memory may be deallocated using free
or finalizerFree
when
no longer required.
callocBytes :: Int -> IO (Ptr a) #
Llike mallocBytes
but memory is filled with bytes of value zero.
realloc :: Storable b => Ptr a -> IO (Ptr b) #
Resize a memory area that was allocated with malloc
or mallocBytes
to the size needed to store values of type b
. The returned pointer
may refer to an entirely different memory area, but will be suitably
aligned to hold values of type b
. The contents of the referenced
memory area will be the same as of the original pointer up to the
minimum of the original size and the size of values of type b
.
If the argument to realloc
is nullPtr
, realloc
behaves like
malloc
.
reallocBytes :: Ptr a -> Int -> IO (Ptr a) #
Resize a memory area that was allocated with malloc
or mallocBytes
to the given size. The returned pointer may refer to an entirely
different memory area, but will be sufficiently aligned for any of the
basic foreign types that fits into a memory block of the given size.
The contents of the referenced memory area will be the same as of
the original pointer up to the minimum of the original size and the
given size.
If the pointer argument to reallocBytes
is nullPtr
, reallocBytes
behaves like malloc
. If the requested size is 0, reallocBytes
behaves like free
.
copyBytes :: Ptr a -> Ptr a -> Int -> IO () #
Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may not overlap
moveBytes :: Ptr a -> Ptr a -> Int -> IO () #
Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may overlap
fillBytes :: Ptr a -> Word8 -> Int -> IO () #
Fill a given number of bytes in memory area with a byte value.
Since: base-4.8.0.0
Free a block of memory that was allocated with malloc
,
mallocBytes
, realloc
, reallocBytes
, new
or any of the new
X functions in Foreign.Marshal.Array or
Foreign.C.String.
mallocArray :: Storable a => Int -> IO (Ptr a) #
Allocate storage for the given number of elements of a storable type
(like malloc
, but for multiple elements).
mallocArray0 :: Storable a => Int -> IO (Ptr a) #
Like mallocArray
, but add an extra position to hold a special
termination element.
allocaArray :: Storable a => Int -> (Ptr a -> IO b) -> IO b #
Temporarily allocate space for the given number of elements
(like alloca
, but for multiple elements).
allocaArray0 :: Storable a => Int -> (Ptr a -> IO b) -> IO b #
Like allocaArray
, but add an extra position to hold a special
termination element.
reallocArray0 :: Storable a => Ptr a -> Int -> IO (Ptr a) #
Adjust the size of an array including an extra position for the end marker.
callocArray :: Storable a => Int -> IO (Ptr a) #
Like mallocArray
, but allocated memory is filled with bytes of value zero.
callocArray0 :: Storable a => Int -> IO (Ptr a) #
Like callocArray0
, but allocated memory is filled with bytes of value
zero.
peekArray :: Storable a => Int -> Ptr a -> IO [a] #
Convert an array of given length into a Haskell list. The implementation is tail-recursive and so uses constant stack space.
peekArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO [a] #
Convert an array terminated by the given end marker into a Haskell list
pokeArray0 :: Storable a => a -> Ptr a -> [a] -> IO () #
Write the list elements consecutive into memory and terminate them with the given marker element
newArray :: Storable a => [a] -> IO (Ptr a) #
Write a list of storable elements into a newly allocated, consecutive
sequence of storable values
(like new
, but for multiple elements).
newArray0 :: Storable a => a -> [a] -> IO (Ptr a) #
Write a list of storable elements into a newly allocated, consecutive sequence of storable values, where the end is fixed by the given end marker
withArray :: Storable a => [a] -> (Ptr a -> IO b) -> IO b #
Temporarily store a list of storable values in memory
(like with
, but for multiple elements).
withArray0 :: Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b #
Like withArray
, but a terminator indicates where the array ends
withArrayLen :: Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b #
Like withArray
, but the action gets the number of values
as an additional parameter
withArrayLen0 :: Storable a => a -> [a] -> (Int -> Ptr a -> IO b) -> IO b #
Like withArrayLen
, but a terminator indicates where the array ends
copyArray :: Storable a => Ptr a -> Ptr a -> Int -> IO () #
Copy the given number of elements from the second array (source) into the first array (destination); the copied areas may not overlap
moveArray :: Storable a => Ptr a -> Ptr a -> Int -> IO () #
Copy the given number of elements from the second array (source) into the first array (destination); the copied areas may overlap
lengthArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO Int #
Return the number of elements in an array, excluding the terminator
advancePtr :: Storable a => Ptr a -> Int -> Ptr a #
Advance a pointer into an array by the given number of elements
Deallocate a memory pool and everything which has been allocated in the pool itself.
withPool :: (Pool -> IO b) -> IO b #
Execute an action with a fresh memory pool, which gets automatically deallocated (including its contents) after the action has finished.
pooledMallocBytes :: Pool -> Int -> IO (Ptr a) #
Allocate the given number of bytes of storage in the pool.
pooledRealloc :: Storable a => Pool -> Ptr a -> IO (Ptr a) #
Adjust the storage area for an element in the pool to the given size of the required type.
pooledReallocBytes :: Pool -> Ptr a -> Int -> IO (Ptr a) #
Adjust the storage area for an element in the pool to the given size.
pooledMallocArray :: Storable a => Pool -> Int -> IO (Ptr a) #
Allocate storage for the given number of elements of a storable type in the pool.
pooledMallocArray0 :: Storable a => Pool -> Int -> IO (Ptr a) #
Allocate storage for the given number of elements of a storable type in the pool, but leave room for an extra element to signal the end of the array.
pooledReallocArray :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a) #
Adjust the size of an array in the given pool.
pooledReallocArray0 :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a) #
Adjust the size of an array with an end marker in the given pool.
pooledNew :: Storable a => Pool -> a -> IO (Ptr a) #
Allocate storage for a value in the given pool and marshal the value into this storage.
pooledNewArray :: Storable a => Pool -> [a] -> IO (Ptr a) #
Allocate consecutive storage for a list of values in the given pool and marshal these values into it.
pooledNewArray0 :: Storable a => Pool -> a -> [a] -> IO (Ptr a) #
Allocate consecutive storage for a list of values in the given pool and marshal these values into it, terminating the end with the given marker.
A signed integral type that can be losslessly converted to and from
Ptr
. This type is also compatible with the C99 type intptr_t
, and
can be marshalled to and from that type safely.
Instances
ptrToIntPtr :: Ptr a -> IntPtr #
casts a Ptr
to an IntPtr
intPtrToPtr :: IntPtr -> Ptr a #
casts an IntPtr
to a Ptr
An unsigned integral type that can be losslessly converted to and from
Ptr
. This type is also compatible with the C99 type uintptr_t
, and
can be marshalled to and from that type safely.
Instances
ptrToWordPtr :: Ptr a -> WordPtr #
casts a Ptr
to a WordPtr
wordPtrToPtr :: WordPtr -> Ptr a #
casts a WordPtr
to a Ptr