newCString -- to 'free' or not?

Bayley, Alistair Alistair_Bayley at ldn.invesco.com
Mon Sep 27 03:42:29 EDT 2004


> And Alistair Reid answers a similar question I asked:

Sorry... s/Alistair/Alastair/

> -----Original Message-----
> From: Bayley, Alistair [mailto:Alistair_Bayley at ldn.invesco.com] 
> Sent: 27 September 2004 08:37
> To: 'Peter Simons'; glasgow-haskell-users at haskell.org
> Subject: RE: newCString -- to 'free' or not?
> 
> There are some useful guidelines hidden in section 8.2.3 of 
> the GHC user's
> guide:
>  
> http://www.haskell.org/ghc/docs/latest/html/users_guide/sec-ff
> i-ghc.html#AEN
> 10578
>  
> And Alistair Reid answers a similar question I asked:
>   http://www.reid-consulting-uk.ltd.uk/docs/ffi-Common_Problems.html
> (Common Problems: Are Ptr values deallocated?)
> 
> 
> In the current CVS code newCString redirects to newCAString, 
> which uses
> mallocArray (or newArray), and which also states that storage 
> must be freed:
>  
> http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/ba
> se/Foreign/C/S
> tring.hs?rev=1.14
> 
> You can also see that Foreign.Marshal.Utils.new uses malloc:
>  
> http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/ba
> se/Foreign/Mar
> shal/Utils.hs?rev=1.12
> 
> 
> 
> > -----Original Message-----
> > From: Peter Simons [mailto:simons at cryp.to] 
> > Sent: 25 September 2004 21:38
> > To: glasgow-haskell-users at haskell.org
> > Subject: newCString -- to 'free' or not?
> > 
> > When I create a CString with Foreign.C.String.newCString, do
> > I have to 'free' it after I don't need it anymore? Or is
> > there some RTS magic taking place?
> > 
> > How about Foreign.Marshal.Utils.new and all those other
> > newXYZ functions? 
> > 
> > Peter

-----------------------------------------
*****************************************************************
Confidentiality Note: The information contained in this 
message, and any attachments, may contain confidential 
and/or privileged material. It is intended solely for the 
person(s) or entity to which it is addressed. Any review, 
retransmission, dissemination, or taking of any action in 
reliance upon this information by persons or entities other 
than the intended recipient(s) is prohibited. If you received
this in error, please contact the sender and delete the 
material from any computer.
*****************************************************************



More information about the Glasgow-haskell-users mailing list