<div dir="ltr">Hi,<div><br></div><div>Matthias, I may have encountered a failure-to-release-no-longer-needed-memory in a test I ran that I'll review in the morning, as I'm very tired now.</div><div><br></div><div>Best regards,</div><div>Robert Buckley</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 30, 2015 at 5:22 PM, Peter Wang <span dir="ltr"><<a href="mailto:novalazy@gmail.com" target="_blank">novalazy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
On Thu, 30 Apr 2015 18:54:29 +0100, Matthias Guedemann <<a href="mailto:matthias.guedemann@googlemail.com">matthias.guedemann@googlemail.com</a>> wrote:<br>
><br>
> I'd be happy to learn more on using FFI. In particular, I think my<br>
> approach is heavy on memory leaks. Every time a new mp_int is created,<br>
> memory is allocated which is never(?) freed. How does one handle this in<br>
> Mercury normally when using FFI?<br>
<br>
</span>You should allocate the mp_ints like this:<br>
<br>
Mp_Int = MR_GC_NEW_ATTRIB(mp_int, MR_ALLOC_ID);<br>
<br>
For the string in mp_to_string you should use<br>
<br>
MR_allocate_aligned_string_msg(S, length, MR_ALLOC_ID);<br>
<br>
or other macros in mercury_string.h<br>
<br>
You should add the attribute `thread_safe' to all of the foreign procs.<br>
<br>
Peter<br>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.mercurylang.org">users@lists.mercurylang.org</a><br>
<a href="https://www.mercurylang.org/lists/listinfo/users" target="_blank">https://www.mercurylang.org/lists/listinfo/users</a><br>
</blockquote></div><br></div>