From: Markus Mottl <markus@mail4.ai.univie.ac.at>
To: Xavier Leroy <Xavier.Leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Module (re)construction cost
Date: Fri, 27 Jul 2001 16:09:55 +0200 [thread overview]
Message-ID: <20010727160955.A2756@kastanie.ai.univie.ac.at> (raw)
In-Reply-To: <20010727152521.A28238@pauillac.inria.fr>; from Xavier.Leroy@inria.fr on Fri, Jul 27, 2001 at 15:25:21 +0200
On Fri, 27 Jul 2001, Xavier Leroy wrote:
> > i.e. does functor
> > application cost anything (time ? memory ?).
>
> Evaluating the functor application itself is very cheap, it just
> builds a tuple of values from a tuple of values. Moreover, this takes
> place at program start-up time, i.e. not often. The main hidden cost
> is the lack of optimization in certain function calls as described
> above.
Unless this functor application is used to create a local module, of
course. Then each call to the enclosing function (and if control flow
actually reaches the functor application) will require the creation of
this tuple.
It should also be noted that this may mean evaluating possibly expensive
expressions whose values will be put into the tuple slots. In fact,
you could even have expressions there that do not terminate at all
or eat up all your memory depending on the parameters passed via the
functor parameter. E.g.:
module type VICE = sig
val sleep : bool
val munch : bool
end
module Make (Vice : VICE) = struct
let _ =
if Vice.munch then
let stomach = ref [] in
for i = 1 to 10000000 do
stomach := () :: !stomach
done;
if Vice.sleep then while true do () done
end
let sin sleep munch =
let module Immoderateness = struct
let munch = munch
let sleep = sleep
end in
let module Cockaigne = Make (Immoderateness) in
()
let _ = sin true true
First the functor application will eat a good share of your memory. Then
it will put your machine to sleep forever...
Regards,
Markus Mottl
--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-07-27 14:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-22 8:18 Berke Durak
2001-07-27 13:25 ` Xavier Leroy
2001-07-27 14:09 ` Markus Mottl [this message]
2001-07-27 17:51 ` William Chesters
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010727160955.A2756@kastanie.ai.univie.ac.at \
--to=markus@mail4.ai.univie.ac.at \
--cc=Xavier.Leroy@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox