From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DBCBBBB83 for ; Fri, 18 Aug 2006 04:41:57 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7I2fvN3006084 for ; Fri, 18 Aug 2006 04:41:57 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA30870 for ; Fri, 18 Aug 2006 04:41:56 +0200 (MET DST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7H5uppB024592 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 17 Aug 2006 07:56:51 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GDarx-0002FT-6o for caml-list@inria.fr; Thu, 17 Aug 2006 07:56:41 +0200 Received: from 0x5731d08c.bynxx18.adsl-dhcp.tele.dk ([87.49.208.140]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 Aug 2006 07:56:41 +0200 Received: from spam by 0x5731d08c.bynxx18.adsl-dhcp.tele.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 Aug 2006 07:56:41 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Bardur Arantsson Subject: Re: Help interfacing with C Date: Thu, 17 Aug 2006 07:56:28 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 0x5731d08c.bynxx18.adsl-dhcp.tele.dk User-Agent: Thunderbird 1.5.0.5 (X11/20060729) In-Reply-To: Sender: news X-Spam: no; 0.00; interfacing:01 pairs:01 descriptors:01 ocaml:01 unix:01 unix:01 allocating:01 iterating:01 descriptors:01 sdu:01 terry:98 wrote:01 slower:01 tar:01 int:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Nathaniel Gray wrote: > Hi folks, [--snip--] > have select work on (file_descr * 'a) pairs instead of plain file > descriptors. It's much easier than that; just define a conversion in OCaml: external file_descr_to_int : file_descr -> int = "%identity"; external int_to_file_descr : int -> file_descr = "%identity"; and use let my_select r w e t = let r' = List.map file_descr_to_int r and w' = List.map file_descr_to_int w and e' = List.map file_descr_to_int e in Unix.select r' w' e' t;; You seem to be doing the mapping of the result values, but that is just a question of mapping int_to_file_descr over the result lists. Of course this may be rather slower than your version, but Unix.select is very very slow anyway since it's allocating at least one list for every single call... and iterating through all(?) the file descriptors in the input FD_SETs as well. [Shameless plug below: If you want better performance, you might want to try http://www.imada.sdu.dk/~bardur/personal/45-programs/ocaml-events/ocaml-events-0.1.0.tar.bz2 I must warn you, though, that there are no timers or signal handling: It turned out I didn't them for my particular application, so I haven't bothered adding support. The actual FD polling/selection has worked very reliably for me.] -- Bardur Arantsson The truth is out there, but lies are in your head. Terry Pratchett, 'Hogfather'