From: Brian H. <bri...@ql...> - 2003-06-20 15:48:01
|
On Fri, 20 Jun 2003, John Max Skaller wrote: > Brian Hurt wrote: > > > >>C++ vector does this correctly. > >> > > > > At the cost of emitting a whole new wad og object code for every single > > type you put into a vector. Vector<int> requires the compiler to produce > > a whole vector class to deal with ints, seperate from Vector<short>, > > Vector<char>, Vector<void *>, etc. > > > Your comparison is unfair and untrue. > > If you make the equivalent vector to ocaml, > you'd make a vector of pointers. It is both fair and true. Notice that the examples I gave, all except void* were unboxed. I don't know how many C++ compilers can figure out that a Vector<foo*> and a Vector<bar*> can use the same object code. I can easily envision tricky code where they couldn't. But I haven't looked recently, so they may (in the cases where they can). > The principal problem in C++ here is the lack of > a garbage collector. If this is the only reason you're using Ocaml and not C++, take a look at: http://www.hpl.hp.com/personal/Hans_Boehm/gc/ Or you might take a gander at this language: http://java.sun.com/ I hear they're adding both templates and operator overloading in the next version. > > In this case, you're going to be using a 'a option Dynarray.t one way or > > another. The question is wether you can ever get rid of the option part. > > > Nah, just box the floats. > Should be easy. Make the underlying array > type int. Use 0 as the null value. > Use casts to convert incoming and outgoing > values. Easy. Floats stay boxed though. > I don't care. > > Don't have casts in Ocaml. I don't know of a way to force unboxing of floats in an array without coding in C. If I could do that, Obj.magic() would work. So we're talking about rewritting the whole thing in C. Could be done. Don't use ints for the array type, use the Value type. But one of the reasons I'm contributing to ExtLib is that I want to do some programming in *Ocaml*. But I'm willing to take it under advisement, and put it on my to do list. Just don't hold your breath. And are you willing to gaurentee that no one will ever care that float Dynarray.t's are boxed? "But float arrays are unboxed! This makes all my data structures 50% larger than they need to be! Bloat! Horror! Dynarrays should work just like arrays, but dynamic!" Brian, who is snarly because he's having to wade through some atrocious C++, and isn't in the mood to listen to people sing hosanahs to the language. |