[m-users.] Too Slow

Julien Fischer jfischer at opturion.com
Wed Apr 15 16:24:30 AEST 2015


Hi,

On Tue, 14 Apr 2015, Delmas Buckley wrote:

> Thanks, Julien. I'm assuming that I can just assign names to the
> integers and use those names to avoid memory usage.
>   Robert Buckley

If you mean this,

     :- func two = integer.

     two = integer(2).

then in general, no, you will still end up calling integer/1 and
allocating memory to construct the constant.

If you mean this:

     Two = integer(2)

and just passing that variable around, then yes.  One thing that can
be done with constant functions whose values you do not want to
re-evaluate is to use tabling, for example:

     :- pragma memo(two/0).
     :- func two = integer.
     two = integer(2).

will allocate memory for the first call to two/0 and then store that
result for use by further calls to two/0.

(Ideally, if --intermodule-optimization were enabled, the compiler would
be able to use inlining and partial evaluation to turn integer(N), where
N is a small constant, into its underlying representation as an integer,
but that doesn't currently happen.)

Cheers,
Julien.



More information about the users mailing list