Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* one-time initialization
@ 1999-01-28  5:08 Michael Hicks
  1999-01-28  9:54 ` John Prevost
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Michael Hicks @ 1999-01-28  5:08 UTC (permalink / raw)
  To: caml-list

I wonder if anyone knows how to optimize the following (simplified for the
sake of dicussion) situation:

let global = ref None
let init i =
  global := Some i
let f () =
  match (!global) with
    Some x -> x
  | None -> failwith "not initialized";;
let g() =
  match (!global) with
    ...

Essentially, there is some global state that is initialized once, and is
used by all functions in the module.  In a more realistic situation, this
state might be initialized by reading in a file.  Given that following
initialization the global state never changes, it should be conceivable to
eliminate the match and dereference; on my machine (pentium 166), the match
and dereference result in about a 30% slowdown.  I've fooled around with
some things, but haven't found anything that performs better than this
straightforward approach or is any more elegant.

Thanks,
Mike
-- 
Michael Hicks
Ph.D. Candidate, the University of Pennsylvania
http://www.cis.upenn.edu/~mwh            mailto://mwh@dsl.cis.upenn.edu
"I worked with an individual who plugged his power strip back into itself
and for the life of him could not understand why his computer would not
turn on."




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-01-29  8:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-28  5:08 one-time initialization Michael Hicks
1999-01-28  9:54 ` John Prevost
1999-01-28 14:47   ` Michael Hicks
1999-01-28 10:38 ` Xavier Leroy
1999-01-28 13:03 ` Adam P. Jenkins
1999-01-28 20:23 ` Gerd Stolpmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox