Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Is anyone using caml for music or sound synthesis?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: William Chesters <williamc@p...>
Subject: Re: [Caml-list] Is anyone using caml for music or sound synthesis?
Markus Mottl writes:
 > On Fri, 09 Aug 2002, Nicolas Cannasse wrote:
 > > Yes but such algorithms are making a large use of float calculations, and
 > > ocaml float are boxed into a block, so such calcs could trigger multiples
 > > allocations.
 > 
 > It's true that this can deteriorate performance in the general case,
 > but note that the compiler performs a fair amount of unboxing (e.g.
 > float arrays when the compiler can see the float type). This usually makes
 > numeric code run surprisingly fast in OCaml. If you know the details, you
 > can most often write your code in such a way that it performs efficiently.
 > Then it really isn't much worse than C.

That's been my experience too.  The main "gotcha" is that when you
write imperative loops you should avoid using "float ref", because
the polymorphism of the 'a ref type prevents float unboxing.  Hence
don't do

  let tot = ref 0. in
  for i = 0 to Array.length a do
    tot := !tot +. a.(i)
  done

but rather

  type floatref = { mutable v: float }

  let tot = { v = 0. } in
  for i = 0 to Array.length a do
    tot.v <- tot.v +. a.(i)
  done

The other thing to remember is that ocaml doesn't do inlining across
compilation boundaries.  If you bear those things in mind, though, it
is fine.  You could probably find cases where ocaml did better than
gcc because of the latter's occasional brainstorms when it comes to
register allocation.
-------------------
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