[Haskell-cafe] FFI: how to allocate a const char * from haskell
PICCA Frederic-Emmanuel
frederic-emmanuel.picca at synchrotron-soleil.fr
Tue Apr 18 13:03:18 UTC 2023
Hello, I need to call a c method which take a const char *
something like
void hkl_holder_add_axis(const struct holder *holder, const char *name);
during all the life of this object, the const char* should be accessible.
So from haskell I need to create a CString which will not be affected by the garbage collection.
The memory should be release only when the given object is freed. or when the program stop.
when I use alloca, the memory is releases and the code segfault.
I think that I could use malloc, but in that case I have a memory leak. (this is not that important in my case, since I create less than 10 of these objects).
I would like you advice in order to solve this properly.
thanks for your help.
Frederic
More information about the Haskell-Cafe
mailing list