<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/01/b1070fc490cf3afca7675fa3eb7dfb03"
  from="Fabrice Le Fessant &lt;fabrice@l...&gt;"
  author="Fabrice Le Fessant"
  date="2003-01-24T10:15:39"
  subject="Re: [Caml-list] file descriptors as integers?"
  prev="2003/01/c7536faa6a91c5b1a83c95b78da4f5fd"
  next="2003/01/ccc2e51cee94b42e99f894931dc700df"
  prev-in-thread="2003/01/d579dc7183e18352238ff4a8f4a069ee"
  prev-thread="2003/01/4a9754e53ff07723caf21b4496d1d267"
  next-thread="2003/01/7af23fdb84955df7febee50c37327874"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] file descriptors as integers?">
<msg 
  url="2003/01/d579dc7183e18352238ff4a8f4a069ee"
  from="Chris Uzdavinis &lt;chris@a...&gt;"
  author="Chris Uzdavinis"
  date="2003-01-24T05:06:46"
  subject="[Caml-list] file descriptors as integers?">
<msg 
  url="2003/01/b1070fc490cf3afca7675fa3eb7dfb03"
  from="Fabrice Le Fessant &lt;fabrice@l...&gt;"
  author="Fabrice Le Fessant"
  date="2003-01-24T10:15:39"
  subject="Re: [Caml-list] file descriptors as integers?">
</msg>
</msg>
</thread>

<contents>

&gt;  The Unix module publishes the type "file_descr" as an abstract type.
&gt;  This makes it difficult to use file descriptors in some (IMHO) useful
&gt;  ways.
&gt;  
&gt;  When I manage a large number of descriptors, an efficient technique to
&gt;  is to use the descriptor as the index into an array of per-connection
&gt;  data structures.  But since the descriptor is abstract, I cannot use
&gt;  it as an integer to do this.
&gt;  
&gt;  I know I can use hash-tables in ocaml to create a similar relationship
&gt;  between (fd,data) but it is less efficient.  Is there any kind of
&gt;  interface to get the integral value of a file descriptor, or perhaps a
&gt;  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

</contents>

</message>

