caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] exception or conditional
@ 2004-02-10 23:07 Chris GauthierDickey
  2004-02-10 23:34 ` Markus Mottl
  0 siblings, 1 reply; 2+ messages in thread
From: Chris GauthierDickey @ 2004-02-10 23:07 UTC (permalink / raw)
  To: caml-list

I'm writing a function that is using an array that can be dynamically 
resized. I'm wondering if it would be better to just catch an exception 
if we attempt to go out of bounds in the array (at which point I resize 
the array), or if I should test the size using an if-then-else before I 
enter the main body of my function and resize then.

How lightweight is the exception mechanism in ocaml? If I test the size, 
then any time I call this function, I have to execute the conditional 
statement. If I use try...with, then I'm entering an exception handling 
block every call to the function. Is one better than the other? Neither 
one makes the code clearer or cleaner, so that's not really a factor.

Thanks in advance for your advice,
Chris G.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] exception or conditional
  2004-02-10 23:07 [Caml-list] exception or conditional Chris GauthierDickey
@ 2004-02-10 23:34 ` Markus Mottl
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Mottl @ 2004-02-10 23:34 UTC (permalink / raw)
  To: Chris GauthierDickey; +Cc: caml-list

On Tue, 10 Feb 2004, Chris GauthierDickey wrote:
> I'm writing a function that is using an array that can be dynamically 
> resized. I'm wondering if it would be better to just catch an exception 
> if we attempt to go out of bounds in the array (at which point I resize 
> the array), or if I should test the size using an if-then-else before I 
> enter the main body of my function and resize then.

You might be interested in the RES-library, which also implements
resizable arrays while staying compatible to the Array-module:

  http://www.oefai.at/~markus/home/ocaml_sources.html#RES

Bounds checking probably makes less difference to the performance of
your algorithm than you might expect.

Regards,
Markus

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2004-02-10 23:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-10 23:07 [Caml-list] exception or conditional Chris GauthierDickey
2004-02-10 23:34 ` Markus Mottl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).