[m-users.] Too Slow

Mark Brown mark at mercurylang.org
Fri May 1 23:23:49 AEST 2015


On Fri, May 1, 2015 at 5:54 PM, Peter Wang <novalazy at gmail.com> wrote:
> On Fri, 01 May 2015 07:02:48 +0100, Matthias Guedemann <matthias.guedemann at googlemail.com> wrote:
>> Hi Peter,
>>
>> > You should allocate the mp_ints like this:
>>
>> >     Mp_Int = MR_GC_NEW_ATTRIB(mp_int, MR_ALLOC_ID);
>>
>> > For the string in mp_to_string you should use
>>
>> >     MR_allocate_aligned_string_msg(S, length, MR_ALLOC_ID);
>>
>> > or other macros in mercury_string.h
>>
>> ok, thank you for the hints. Could you point me to the relevant section
>> in the user guide, or is the documentation only in the source files?
>
> Unfortunately the latter (mercury_memory.h and mercury_string.h).
> I think no memory management interface has been documented because
> the existing interface is specific to conservative GCs, if not Boehm
> GC.  Nonetheless, practical code using the foreign language interface
> invariably needs to allocate so I think we should document some of the
> macros and functions, with caveats.

That's done for lists and floats (section 14.3.1), and ought to be
done for strings, too. Allocating foreign types on Mercury's heap
needs one big caveat, though, namely that no finaliser will be called.
If the foreign type needs to be explicitly freed, allocating it on
Mercury's heap won't work.

Unfortunately, libtommath falls into this category - it expects
mp_ints to be cleared when they're done with. So the code still leaks
even with the above changes.

Cheers,
Mark.



More information about the users mailing list