From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Scott Subject: Re: [PATCH 22/28] libxl: ocaml: event management Date: Tue, 26 Mar 2013 12:03:41 +0000 Message-ID: <51518E9D.9060906@eu.citrix.com> References: <1364222729-6982-1-git-send-email-rob.hoes@citrix.com> <1364222729-6982-23-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1364222729-6982-23-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Rob Hoes Cc: Ian Campbell , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On 25/03/13 14:45, Rob Hoes wrote: > +void fd_deregister(void *user, int fd, void *for_app_registration) > +{ > + CAMLparam0(); > + CAMLlocalN(args, 2); > + value *func = caml_named_value("fd_deregister"); > + > + args[0] = (value) user; > + args[1] = Val_int(fd); > + > + caml_callbackN(*func, 2, args); > + CAMLreturn0; > +} The OCaml manual[*] (S19.7.2) hints that the name lookup is a bit slow: "The pointer returned by caml_named_value is constant and can safely be cached in a C variable to avoid repeated name lookups. On the other hand, the value pointed to can change during garbage collection and must always be recomputed at the point of use." The manual suggests caching the value * in a static like this: void fd_deregister(void *user, int fd, void *for_app_registration) { CAMLparam0(); CAMLlocalN(args, 2); static value * func = NULL; if (func == NULL) { /* First time around, look up by name */ func = caml_named_value("fd_deregister"); } ... [*] http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual033.html