From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id C43B3BC6B for ; Tue, 9 Oct 2007 17:18:46 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACg4C0dAahQhh2dsb2JhbACOSAIBCAop X-IronPort-AV: E=Sophos;i="4.21,249,1188770400"; d="scan'208";a="2781939" Received: from mail.cs.unm.edu ([64.106.20.33]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Oct 2007 17:18:46 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.cs.unm.edu (Postfix) with ESMTP id A6F26E4152; Tue, 9 Oct 2007 09:18:44 -0600 (MDT) Received: from mail.cs.unm.edu ([127.0.0.1]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 19594-02; Tue, 9 Oct 2007 09:18:44 -0600 (MDT) Received: from cs.unm.edu (webmail.cs.unm.edu [64.106.20.39]) by mail.cs.unm.edu (Postfix) with ESMTP id 122EEE4145; Tue, 9 Oct 2007 09:18:44 -0600 (MDT) From: "William D. Neumann" To: Jon Harrop , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Correct way of programming a CGI script Date: Tue, 9 Oct 2007 10:18:49 -0500 Message-Id: <20071009151808.M4217@cs.unm.edu> In-Reply-To: <200710091456.37798.jon@ffconsultancy.com> References: <1191859489.10162.16.camel@localhost.localdomain> <200710091456.37798.jon@ffconsultancy.com> X-Mailer: Open WebMail 2.50 20050106 X-OriginatingIP: 205.175.225.22 (wneumann) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at cs.unm.edu X-Spam: no; 0.00; 0100,:01 byte:01 ocaml:01 ocaml:01 byte:01 arrays:01 arrays:01 bigarrays:01 wrote:01 caml-list:01 functions:01 arithmetic:01 arithmetic:01 int:01 int:01 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