newCString -- to 'free' or not?

2004-09-25 Thread Peter Simons
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

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: newCString -- to 'free' or not?

2004-09-25 Thread Glynn Clements

Peter Simons wrote:

 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? 

Yes. The new* functions allocate the memory with malloc, and you have
to free it yourself. OTOH, the with* functions allocate the memory
with alloca, and it is freed automatically.

Also, a ForeignPtr includes a finaliser which will free the data
automatically when it is no longer referenced.

-- 
Glynn Clements [EMAIL PROTECTED]
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users