(Ptr a -> IO b) -> IO b
The pointer to the array contents is obtained by withStorableArray. The idea is similar to ForeignPtr (used internally here). The pointer should be used only during execution of the IO action retured by the function passed as argument to withStorableArray.
allocaBytes n f executes the computation f, 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.
This is a way to look at the pointer living inside a foreign object. This function takes a function which is applied to that pointer. The resulting IO action is then executed. The foreign object is kept alive at least during the whole action, even if it is not used directly inside. Note that it is not safe to return the pointer from the action and use it after the action completes. All uses of the pointer should be inside the withForeignPtr bracket. The reason for this unsafeness is the same as for unsafeForeignPtrToPtr below: the finalizer may run earlier than expected, because the compiler can only track usage of the ForeignPtr object, not a Ptr object made from it.
This function is normally used for marshalling data to or from the object pointed to by the ForeignPtr, using the operations from the Storable class.
alloca f executes the computation f, 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.
Converts a withXXX combinator into one marshalling a value wrapped into a Maybe, using nullPtr to represent Nothing.
with val f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory into which val has been marshalled (the combination of alloca and poke).
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.
Temporarily allocate space for the given number of elements (like Foreign.Marshal.Alloc.alloca, but for multiple elements).
Like allocaArray, but add an extra position to hold a special termination element.
Temporarily store a list of storable values in memory (like Foreign.Marshal.Utils.with, but for multiple elements).
O(1) construction Use a ByteString with a function requiring a CString.
This function does zero copying, and merely unwraps a ByteString to appear as a CString. It is unsafe in two ways:
* After calling this function the CString shares the underlying byte buffer with the original ByteString. Thus modifying the CString, either in C, or using poke, will cause the contents of the ByteString to change, breaking referential transparency. Other ByteStrings created by sharing (such as those produced via take or drop) will also reflect these changes. Modifying the CString will break referential transparency. To avoid this, use useAsCString, which makes a copy of the original ByteString.
* CStrings are often passed to functions that require them to be null-terminated. If the original ByteString wasn't null terminated, neither will the CString be. It is the programmers responsibility to guarantee that the ByteString is indeed null terminated. If in doubt, use useAsCString.
O(n) construction Use a ByteString with a function requiring a null-terminated CString. The CString will be freed automatically. This is a memcpy(3).
Marshal a Haskell string into a NUL terminated C string using temporary storage.
* the Haskell string may not contain any NUL characters
* the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.
Marshal a Haskell string into a NUL terminated C string using temporary storage.
* the Haskell string may not contain any NUL characters
* the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.
Show more results