<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--Rendered using the Haskell Html Library v0.2--> <HTML ><HEAD ><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" ><TITLE >Foreign.Marshal.Alloc</TITLE ><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css" ><SCRIPT SRC="haddock-util.js" TYPE="text/javascript" ></SCRIPT ><SCRIPT TYPE="text/javascript" >window.onload = function () {setSynopsis("mini_Foreign-Marshal-Alloc.html")};</SCRIPT ></HEAD ><BODY ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="topbar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" " ></TD ><TD CLASS="title" >base-4.2.0.2: Basic libraries</TD ><TD CLASS="topbut" ><A HREF="index.html" >Contents</A ></TD ><TD CLASS="topbut" ><A HREF="doc-index.html" >Index</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="modulebar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><FONT SIZE="6" >Foreign.Marshal.Alloc</FONT ></TD ><TD ALIGN="right" ><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="infohead" >Portability</TD ><TD CLASS="infoval" >portable</TD ></TR ><TR ><TD CLASS="infohead" >Stability</TD ><TD CLASS="infoval" >provisional</TD ></TR ><TR ><TD CLASS="infohead" >Maintainer</TD ><TD CLASS="infoval" >ffi@haskell.org</TD ></TR ></TABLE ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="section4" ><B >Contents</B ></TD ></TR ><TR ><TD ><DL ><DT ><A HREF="#1" >Memory allocation </A ></DT ><DD ><DL ><DT ><A HREF="#2" >Local allocation </A ></DT ><DT ><A HREF="#3" >Dynamic allocation </A ></DT ></DL ></DD ></DL ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Description</TD ></TR ><TR ><TD CLASS="doc" >Marshalling support: basic routines for memory allocation </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Synopsis</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="#v%3Aalloca" >alloca</A > :: <A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A > a => (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > b) -> <A HREF="System-IO.html#t%3AIO" >IO</A > b</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AallocaBytes" >allocaBytes</A > :: <A HREF="Data-Int.html#t%3AInt" >Int</A > -> (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > b) -> <A HREF="System-IO.html#t%3AIO" >IO</A > b</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amalloc" >malloc</A > :: <A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A > a => <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AmallocBytes" >mallocBytes</A > :: <A HREF="Data-Int.html#t%3AInt" >Int</A > -> <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Arealloc" >realloc</A > :: <A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A > b => <A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > b)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AreallocBytes" >reallocBytes</A > :: <A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="Data-Int.html#t%3AInt" >Int</A > -> <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afree" >free</A > :: <A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AfinalizerFree" >finalizerFree</A > :: <A HREF="Foreign-ForeignPtr.html#t%3AFinalizerPtr" >FinalizerPtr</A > a</TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="1" ><A NAME="1" >Memory allocation </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="2" ><A NAME="2" >Local allocation </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:alloca" ><A NAME="v%3Aalloca" ></A ></A ><B >alloca</B > :: <A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A > a => (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > b) -> <A HREF="System-IO.html#t%3AIO" >IO</A > b</TD ></TR ><TR ><TD CLASS="doc" ><P ><TT ><TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Aalloca" >alloca</A ></TT > f</TT > executes the computation <TT >f</TT >, passing as argument a pointer to a temporarily allocated block of memory sufficient to hold values of type <TT >a</TT >. </P ><P >The memory is freed when <TT >f</TT > terminates (either normally or via an exception), so the pointer passed to <TT >f</TT > must <EM >not</EM > be used after this. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:allocaBytes" ><A NAME="v%3AallocaBytes" ></A ></A ><B >allocaBytes</B > :: <A HREF="Data-Int.html#t%3AInt" >Int</A > -> (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > b) -> <A HREF="System-IO.html#t%3AIO" >IO</A > b</TD ></TR ><TR ><TD CLASS="doc" ><P ><TT ><TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AallocaBytes" >allocaBytes</A ></TT > n f</TT > executes the computation <TT >f</TT >, passing as argument a pointer to a temporarily allocated block of memory of <TT >n</TT > 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. </P ><P >The memory is freed when <TT >f</TT > terminates (either normally or via an exception), so the pointer passed to <TT >f</TT > must <EM >not</EM > be used after this. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="3" ><A NAME="3" >Dynamic allocation </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:malloc" ><A NAME="v%3Amalloc" ></A ></A ><B >malloc</B > :: <A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A > a => <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a)</TD ></TR ><TR ><TD CLASS="doc" ><P >Allocate a block of memory that is sufficient to hold values of type <TT >a</TT >. The size of the area allocated is determined by the <TT ><A HREF="Foreign-Storable.html#v%3AsizeOf" >sizeOf</A ></TT > method from the instance of <TT ><A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A ></TT > for the appropriate type. </P ><P >The memory may be deallocated using <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Afree" >free</A ></TT > or <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AfinalizerFree" >finalizerFree</A ></TT > when no longer required. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:mallocBytes" ><A NAME="v%3AmallocBytes" ></A ></A ><B >mallocBytes</B > :: <A HREF="Data-Int.html#t%3AInt" >Int</A > -> <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a)</TD ></TR ><TR ><TD CLASS="doc" ><P >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. </P ><P >The memory may be deallocated using <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Afree" >free</A ></TT > or <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AfinalizerFree" >finalizerFree</A ></TT > when no longer required. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:realloc" ><A NAME="v%3Arealloc" ></A ></A ><B >realloc</B > :: <A HREF="Foreign-Storable.html#t%3AStorable" >Storable</A > b => <A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > b)</TD ></TR ><TR ><TD CLASS="doc" ><P >Resize a memory area that was allocated with <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Amalloc" >malloc</A ></TT > or <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AmallocBytes" >mallocBytes</A ></TT > to the size needed to store values of type <TT >b</TT >. The returned pointer may refer to an entirely different memory area, but will be suitably aligned to hold values of type <TT >b</TT >. 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 <TT >b</TT >. </P ><P >If the argument to <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Arealloc" >realloc</A ></TT > is <TT ><A HREF="Foreign-Ptr.html#v%3AnullPtr" >nullPtr</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Arealloc" >realloc</A ></TT > behaves like <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Amalloc" >malloc</A ></TT >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:reallocBytes" ><A NAME="v%3AreallocBytes" ></A ></A ><B >reallocBytes</B > :: <A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="Data-Int.html#t%3AInt" >Int</A > -> <A HREF="System-IO.html#t%3AIO" >IO</A > (<A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a)</TD ></TR ><TR ><TD CLASS="doc" ><P >Resize a memory area that was allocated with <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Amalloc" >malloc</A ></TT > or <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AmallocBytes" >mallocBytes</A ></TT > 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. </P ><P >If the pointer argument to <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AreallocBytes" >reallocBytes</A ></TT > is <TT ><A HREF="Foreign-Ptr.html#v%3AnullPtr" >nullPtr</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AreallocBytes" >reallocBytes</A ></TT > behaves like <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Amalloc" >malloc</A ></TT >. If the requested size is 0, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AreallocBytes" >reallocBytes</A ></TT > behaves like <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Afree" >free</A ></TT >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:free" ><A NAME="v%3Afree" ></A ></A ><B >free</B > :: <A HREF="Foreign-Ptr.html#t%3APtr" >Ptr</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" >Free a block of memory that was allocated with <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Amalloc" >malloc</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AmallocBytes" >mallocBytes</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Arealloc" >realloc</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AreallocBytes" >reallocBytes</A ></TT >, Foreign.Marshal.Utils.new or any of the <TT >new</TT ><EM >X</EM > functions in <A HREF="Foreign-Marshal-Array.html" >Foreign.Marshal.Array</A > or <A HREF="Foreign-C-String.html" >Foreign.C.String</A >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:finalizerFree" ><A NAME="v%3AfinalizerFree" ></A ></A ><B >finalizerFree</B > :: <A HREF="Foreign-ForeignPtr.html#t%3AFinalizerPtr" >FinalizerPtr</A > a</TD ></TR ><TR ><TD CLASS="doc" >A pointer to a foreign function equivalent to <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Afree" >free</A ></TT >, which may be used as a finalizer (cf Foreign.ForeignPtr.ForeignPtr) for storage allocated with <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Amalloc" >malloc</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AmallocBytes" >mallocBytes</A ></TT >, <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3Arealloc" >realloc</A ></TT > or <TT ><A HREF="Foreign-Marshal-Alloc.html#v%3AreallocBytes" >reallocBytes</A ></TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="botbar" >Produced by <A HREF="http://www.haskell.org/haddock/" >Haddock</A > version 2.6.1</TD ></TR ></TABLE ></BODY ></HTML >