From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q32LFNP7018595 for ; Mon, 2 Apr 2012 23:15:25 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsQDAHz4eU/Unw4Ujmdsb2JhbABFpimRUyIBAQEBCQsJCRIGI4IJAQEFCAIwNBcBAwIJDgMEAQEBDRoHGSwBCQgCBAESCwUCCIdzB7pYinqFdASNa4kHkgaBWw X-IronPort-AV: E=Sophos;i="4.75,358,1330902000"; d="scan'208";a="138770901" Received: from avasout08.plus.net ([212.159.14.20]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Apr 2012 23:15:24 +0200 Received: from WinEight ([87.114.112.81]) by avasout08 with smtp id t9FN1i0031lRaPK019FPDs; Mon, 02 Apr 2012 22:15:24 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=I8Dntacg c=1 sm=1 a=SNaS5AyKB+UI9Kq+unAWQg==:17 a=-tnAv0XnCDgA:10 a=Xub9RBUEA-sA:10 a=kj9zAlcOel0A:10 a=SGJpDYsEAAAA:8 a=ZOzjf2MOAAAA:8 a=CjxXgO3LAAAA:8 a=PrCVO86orOh0kYKJay0A:9 a=SdW9BTy6fIdeNNktFHUA:7 a=CjuIK1q_8ugA:10 a=dTth3pfvbawA:10 a=1CkXkM7HNqP2Dw45:21 a=Ki-PFQ4HIrNQNUIM:21 a=SNaS5AyKB+UI9Kq+unAWQg==:117 From: "Jon Harrop" To: "'David Allsopp'" , "'Hongbo Zhang'" , "'Caml List'" References: <4F79B858.2090502@gmail.com> In-Reply-To: Date: Mon, 2 Apr 2012 22:15:20 +0100 Message-ID: <024101cd1115$b6962110$23c26330$@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKchNmV+F/TI7QyZT9tQ+Lj0w4DWwFb478hlN5Bx5A= Content-Language: en-gb Subject: RE: [Caml-list] How could I implement an efficient ring buffer? The "mod" and the write barrier will significantly degrade performance vs C. Probably faster to replace "mod" with if-based wrap around but there's nothing you can do about the write barrier. Cheers, Jon. > -----Original Message----- > From: David Allsopp [mailto:dra-news@metastack.com] > Sent: 02 April 2012 16:05 > To: Hongbo Zhang; Caml List > Subject: RE: [Caml-list] How could I implement an efficient ring buffer? > > Hongbo Zhang wrote: > > Hi List, > > I want to implement sliding window algorithm (in place, no memory > > copy), I wonder whether I need to write c code. > > > > To make it clear and simple, > > In c, you can record the head pointer of the array, and do the > > modulo operations when get and set > > In ocaml, it seems you have an array a of type int array, you > > can not do things like this *(&a+5). > > Perhaps I'm missing something, but if you're planning on using arrays, what's > wrong with retrieving the item using the array index modulo the length of the > array? > > i.e. > > let a = [| ... or whatever ... |] in > a.(5 mod Array.length a) > > If accessing an array by index instead of by pointer worries you, then you're > looking at the wrong language ;o) > > > David > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs