Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Fabrice Le Fessant <fabrice@lefessant.net>
To: Chris Uzdavinis <chris@atdesk.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] file descriptors as integers?
Date: Fri, 24 Jan 2003 10:18:33 +0100	[thread overview]
Message-ID: <15921.1257.263109.387451@lachesis.inria.fr> (raw)
In-Reply-To: <j6d6mnqgpp.fsf@explicit.atdesk.com>


>  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


      reply	other threads:[~2003-01-24 10:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-24  5:06 Chris Uzdavinis
2003-01-24  9:18 ` Fabrice Le Fessant [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15921.1257.263109.387451@lachesis.inria.fr \
    --to=fabrice@lefessant.net \
    --cc=caml-list@inria.fr \
    --cc=chris@atdesk.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox