Browse thread
Correct way of programming a CGI script
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | William D. Neumann <wneumann@c...> |
| Subject: | Re: [Caml-list] Correct way of programming a CGI script |
On Tue, 9 Oct 2007 14:56:37 +0100, Jon Harrop wrote > In this context, yes. In general, strings are not as efficient as > the equivalent concrete data structure in C. Specifically, using > strings as a byte array and applying arithmetic operations to the > elements is significantly slower in OCaml than C. > > The only option you have in OCaml is to blow your memory wad and use > an int array, which is fast but wastes enormous amounts of space and > still has different modulo-arithmetic properties (you might want 8- > bit for some apps). Consequently, OCaml is not very good for > arithmetic operations over byte arrays. I'd moaned about this a few years ago, and Xavier pointed out the following: "A better alternative is to declare external get_byte: string -> int -> int = "%string_safe_get" external set_byte: string -> int -> int -> unit = "%string_safe_set" and use these two functions to access strings as if they were byte arrays. set_byte will store the low 8 bits of its third argument, so you'd save on "land 0xFF" operations too." It works pretty well for getting and setting bytes of a string. There's also the int8_* bigarrays, but I've not used them much, so I can't say if they're of much help, but they certainly weren't horrible. -- William D. Neumann