From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA11070; Fri, 24 Jan 2003 11:15:39 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA12128 for ; Fri, 24 Jan 2003 11:15:38 +0100 (MET) Received: from lachesis.inria.fr (lachesis.inria.fr [128.93.52.5]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h0OAFVr12379; Fri, 24 Jan 2003 11:15:31 +0100 (MET) Received: (from lefessan@localhost) by lachesis.inria.fr (8.12.5/8.12.5/Submit) id h0O9IY9q006437; Fri, 24 Jan 2003 10:18:34 +0100 From: Fabrice Le Fessant Message-ID: <15921.1257.263109.387451@lachesis.inria.fr> Date: Fri, 24 Jan 2003 10:18:33 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Chris Uzdavinis Cc: caml-list@inria.fr Subject: Re: [Caml-list] file descriptors as integers? References: X-Mailer: VM 7.07 under Emacs 21.2.1 Reply-To: fabrice@lefessant.net Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > The Unix module publishes the type "file_descr" as an abstract type. > This makes it difficult to use file descriptors in some (IMHO) useful > ways. > > When I manage a large number of descriptors, an efficient technique to > is to use the descriptor as the index into an array of per-connection > data structures. But since the descriptor is abstract, I cannot use > it as an integer to do this. > > I know I can use hash-tables in ocaml to create a similar relationship > between (fd,data) but it is less efficient. Is there any kind of > interface to get the integral value of a file descriptor, or perhaps a > more encapsulated way to accomplish a similar result? I don't see why you cannot put the file_descr in a bigger structure with another counter, and use this counter instead of the file_descr number. Anyway, this beautiful function should do the trick (at least, on Unix systems): let fd_num (fd : Unix.file_descr)= (Obj.magic fd : int) - Fabrice ------------------- 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